Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unsubscribe error #74

Open
dimafern opened this issue Oct 2, 2012 · 8 comments
Open

unsubscribe error #74

dimafern opened this issue Oct 2, 2012 · 8 comments
Labels

Comments

@dimafern
Copy link

dimafern commented Oct 2, 2012

Example code:

$channel = $this->rediska->subscribe('bets', $sleeptime);
$channel->unsubscribe();

This will cause:

PHP Fatal error:  Uncaught exception 'Rediska_PubSub_Exception' with message 'Can't find connection 'localhost:6379'' in /Users/fern/workspace/golpas2pg/share/PEAR/Rediska/PubSub/Connections.php:167
Stack trace:
#0 /Users/fern/workspace/golpas2pg/share/PEAR/Rediska/PubSub/Channel.php(462): Rediska_PubSub_Connections->getConnectionByAlias('localhost:6379')
#1 /Users/fern/workspace/golpas2pg/share/PEAR/Rediska/PubSub/Channel.php(148): Rediska_PubSub_Channel->_execCommand('unsubscribe', Array)
#2 /Users/fern/workspace/golpas2pg/share/lib/Gp/Casino/Roulette/Daemon/Run.php(184): Rediska_PubSub_Channel->unsubscribe()

If you do not do unsubscribe(), subscribe connection will nor be closed and you will get "too many files open" in several hours (depending on your sleeptime).

Here is the fix on code:

Channel.php:462

        if (!$connection)
            $connection = $this->_connections->getConnectionByAlias($connectionAlias);

Channel.php:471

        if (!$connection)
            $connection = $this->_connections->getConnectionByAlias($connectionAlias);

There was an error because with unsubscribe the channel is removed from arrays with previous line

                    $connection = $this->_connections->removeChannel($channel);

and getConnectionByAlias can not find it (it is already removed).
$connection is returned by methods and there is no need to search for it again.

@till
Copy link
Collaborator

till commented Oct 10, 2012

Would you mind sending a PR?

@till
Copy link
Collaborator

till commented Oct 10, 2012

And please include a small test case.

@dimafern
Copy link
Author

sorry, what is PR? And what test case do you need? There is a 2 line example code that will give you an error.

@till
Copy link
Collaborator

till commented Oct 10, 2012

PR = pull request

@till
Copy link
Collaborator

till commented Oct 10, 2012

The test case ensures it stays fixed and doesn't break other code.

@dimafern
Copy link
Author

I'm sorry, but i cant see how to send PR. Maybe I do not have priviliges? I'm new to github. Just noticed a bug and fixed it for myself, then shared it in these issues.

@till
Copy link
Collaborator

till commented Oct 10, 2012

The most simple way is clicking 'edit' directly at the files on github and doing your changes there.

It would fork the repo and automatically create a branch with your changes (patch-X) and a PR.

The longer:

  • fork this repo (shumkov/rediska) to your account
  • clone it to your disk
  • make a branch
  • do your commits
  • add a test case
  • push the branch to your repo
  • click "create pull-request" on your repo (to send a PR from your branch to shumkov/rediska/master)

@dimafern
Copy link
Author

PR done, thanks for such a detailed description.
test case is left, how to do it? )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants