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

Connection loss problem #37

Open
juklicek opened this issue Aug 29, 2019 · 3 comments
Open

Connection loss problem #37

juklicek opened this issue Aug 29, 2019 · 3 comments

Comments

@juklicek
Copy link

Hello, we are using stable (6.4) pecl package of your Zookeeper client and we have a issue.
I have a just this simple code:

<?php
$zk = new \Zookeeper("sc1.clapix.com:2181,sc2.clapix.com:2181,sc3.clapix.com:2181/solr");
$zk->setDebugLevel(\Zookeeper::LOG_LEVEL_DEBUG);
$x = $zk->exists('/aliases.json');

var_dump($zk->get('/aliases.json'));

Everything works well till I stop on one of three ZK instance on our servers.

Then I get this sometime:

2019-08-29 16:27:03,228:25057(0x7f2f104b9700):ZOO_DEBUG@get_next_server_in_reconfig@1310: [OLD] count=0 capacity=0 next=0 hasnext=0
2019-08-29 16:27:03,228:25057(0x7f2f104b9700):ZOO_DEBUG@get_next_server_in_reconfig@1313: [NEW] count=3 capacity=16 next=0 hasnext=1
2019-08-29 16:27:03,228:25057(0x7f2f104b9700):ZOO_DEBUG@get_next_server_in_reconfig@1322: Using next from NEW=193.86.66.217:2181
2019-08-29 16:27:03,228:25057(0x7f2f104b9700):ZOO_DEBUG@zookeeper_connect@2210: [zk] connect()

2019-08-29 16:27:03,228:25057(0x7f2f2ccc0880):ZOO_DEBUG@zoo_awexists@3696: Sending request xid=0x5d67e0b8 for path [/aliases.json] to 193.86.66.217:2181
2019-08-29 16:27:03,229:25057(0x7f2f104b9700):ZOO_ERROR@handle_socket_error_msg@2444: Socket [193.86.66.217:2181] zk retcode=-4, errno=111(Connection refused): server refused to accept the client
2019-08-29 16:27:03,229:25057(0x7f2f104b9700):ZOO_DEBUG@cleanup@1763: Previous connection=[193.86.66.217:2181] delay=0
PHP Fatal error:  Uncaught ZookeeperConnectionException: connection loss in /home/jjuklicek/zktest.php:5
Stack trace:
#0 /home/jjuklicek/zktest.php(5): Zookeeper->exists('/aliases.json')
#1 {main}
  thrown in /home/jjuklicek/zktest.php on line 5

Fatal error: Uncaught ZookeeperConnectionException: connection loss in /home/jjuklicek/zktest.php:5
Stack trace:
#0 /home/jjuklicek/zktest.php(5): Zookeeper->exists('/aliases.json')
#1 {main}
  thrown in /home/jjuklicek/zktest.php on line 5
2019-08-29 16:27:03,229:25057(0x7f2f104b9700):ZOO_DEBUG@get_next_server_in_reconfig@1310: [OLD] count=0 capacity=0 next=0 hasnext=0
2019-08-29 16:27:03,230:25057(0x7f2f104b9700):ZOO_DEBUG@get_next_server_in_reconfig@1313: [NEW] count=3 capacity=16 next=1 hasnext=1
2019-08-29 16:27:03,230:25057(0x7f2f104b9700):ZOO_DEBUG@get_next_server_in_reconfig@1322: Using next from NEW=193.86.66.215:2181
2019-08-29 16:27:03,230:25057(0x7f2f104b9700):ZOO_DEBUG@zookeeper_connect@2210: [zk] connect()

2019-08-29 16:27:03,230:25057(0x7f2f104b9700):ZOO_DEBUG@do_io@458: IO thread terminated
2019-08-29 16:27:03,230:25057(0x7f2f0fcb8700):ZOO_DEBUG@do_completion@481: completion thread terminated
2019-08-29 16:27:03,230:25057(0x7f2f2ccc0880):ZOO_INFO@zookeeper_close@3271: Freeing zookeeper resources for sessionId=0

Do you have some idea what is wrong? Is that right that one of three ZK instance failure should be ok for the client?

Thank you very much!

@Timandes
Copy link
Member

Timandes commented Sep 17, 2019

Sorry for my late reply.
I need some time to reproduce this scenario in order to find some possibilities to this issue.

The following description is WRONG, please ignore it (Edited by Timandes on 2019-9-19):

FYI, Zookeeper::connect() does not actually connect to one of the servers as you call it.
Lazy connection will be established when real needs meet.

@juklicek
Copy link
Author

Hallo and thank you. Yes, we would like to know how it was meant and how we should use it correctly?
We find out, that this happen only when first connection is established. When, we are working with existing connection (\Zookeeper instance) it works fine as expected. But, you know how php basically works - everything is established again with every request, so this is not very helpful for us...

@Timandes
Copy link
Member

Try this:

<?php

\Zookeeper::setDebugLevel(\Zookeeper::LOG_LEVEL_DEBUG);

// Create instance and register connection callback
$zk = new \Zookeeper("127.0.0.1:2181,127.0.0.2:2182,127.0.0.3:2183",
    function($type, $state) {
        global $zk;
        if ($state == \Zookeeper::CONNECTED_STATE) {
            // We can do other stuff after connection established
            $x = $zk->exists('/aliases.json');
            var_dump($zk->get('/aliases.json'));

            // Stop loop
            exit;
        }
    });

// Loop and dispatch events
while(true) {
    \Zookeeper::dispatch();
    sleep(1);
}

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

No branches or pull requests

2 participants