exit() hangs when called after getSocket(ZMQ::SOCKET_PULL) but NOT after getSocket(ZMQ::SOCKET_PUSH) #548
-
When I was trying to debug some PHP script that doesn't terminate as expected, I tracked down the problem to be something related ReactPHP and ZMQ. When exit() is called after getSocket(ZMQ::SOCKET_PULL), PHP script will hang. A minimum test code is included below: use React\ZMQ\Context;
require dirname(__DIR__).'/vendor/autoload.php';
$testLoop = React\EventLoop\Loop::get();
$testContext = new Context($testLoop);
$testPusher = $testContext->getSocket(ZMQ::SOCKET_PUSH);
$testPusher->bind('tcp://127.0.0.1:5555');
//exit("exited after ZMQ:SOCKET_PUSH / before ZMQ::SOCKET_PULL\r\n");
$testPuller = $testContext->getSocket(ZMQ::SOCKET_PULL);
exit("tried to exit after ZMQ::SOCKET_PULL\r\n");
$testPuller->bind('tcp://127.0.0.1:5557'); Running the script above yields the following output in terminal:
The above code is tested on Ubuntu 20.04 with PHP7.4,React/ZMQ 0.4.0 (2018-05-18) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hey @zhiyong-ft, thanks for bringing this up 👍 Not an ZMQ expert here, but I think if you want to pull something you have to wait for the incoming data until they arrive (same goes for readable streams). This is why it seems like the script hangs, when it is actually just waiting for data. However, this is not the case for a push operation. Once the data you wish to send out is pushed, the operation is considered complete. FYI: I think this kind of ticket is better suited for a discussion in our "Q&A" section, this is why I converted the original issue into a discussion. We recommend opening bug tickets only when you can provide evidence of something being broken, just as a friendly reminder for future tickets :) Hope this helps :) |
Beta Was this translation helpful? Give feedback.
-
@SimonFrings Thanks for your reply. I don't know enough about PHP/ZMQ to agree/disagree with your explanation about why script hangs. But the fact that script doesn't terminate after exit() is called is a bit alarming. When exception happens, we may rely on calling exit() to terminate a script then restart it by other tools like supervisor or similar. Imagine what happens when long running scripts don't auto-restart. |
Beta Was this translation helpful? Give feedback.
@zhiyong-ft It looks like you may want to use
Loop::run()
orLoop::stop()
if you don't want to rely on loop autorun in this case. I'm not sure what problem you're seeing exactly and what your expected output would be in this case, but ReactPHP gives you full control over these low-level details if needed for more advanced use cases.