Warning when calling close on Websocket\Client
elovin opened this issue · 5 comments
I have a custom error_handler to re throw warnings as Exceptions, but when I do that I get a strange exception/warning on $client->close() (Websocket\Client):
Exception: Expected either valid PHP stream or valid PHP socket resource in /ws/vendor/amphp/amp/lib/Loop/EventDriver.php on line 245
Call Stack:
0.0046 401960 1. {main}() /ws/src/WebsocketServerHandler.php:0
0.1001 5977296 2. Amp\Loop::run(???) /ws/src/WebsocketServerHandler.php:74
0.1001 5977896 3. Amp\Loop\EventDriver->run() /ws/vendor/amphp/amp/lib/Loop.php:84
0.1001 5977896 4. Amp\Loop\EventDriver->run() /ws/vendor/amphp/amp/lib/Loop/EventDriver.php:180
11.5208 7972936 5. Amp\Loop\EventDriver->tick() /ws/vendor/amphp/amp/lib/Loop/Driver.php:72
11.5209 7972560 6. Amp\Loop\EventDriver->activate(???) /ws/vendor/amphp/amp/lib/Loop/Driver.php:105
11.5210 7972880 7. Event->__construct(???, ???, ???, ???, ???) /ws/vendor/amphp/amp/lib/Loop/EventDriver.php:245
I disabled the xdebug and event extension and changed the php.ini to production (offical docker cli container) but that did not change the warning.
Am I missing something or is this expected behavior ?
I guess you're also converting suppressed errors to exceptions?
@kelunik
No only E_ERROR but I was wrong, the warning only occurs when the xdebug extension is enabled.
set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) { // some error handling... }, E_WARNING);
Okay I tested multiple error types and its not a warning rethrown as an error its just an Exception that is thrown when xdebug is enabled and an error handler defined.
Okay im not sure why but this error only occurres when I set the error handler in the ClientHandler.
Could you push a full example somewhere?
I will try to get a working example, right now after more testing I can say that it has nothing to do with the error handler, whenever I debug my second ws server I get this error. If I turn off debugging I wont get the error. My setup is however quite uncommon I guess, I use two websocket servers one simply receives messages from the local network (another container) In case the other ws server (the one who handles the actual clients) should restart because some php files changed (this sounds dangerous but In this setup only the admin container can actually do that).
To do that I use amps process lib to run the child ws server in another process and to send and receive the sigterm.
The master ws server does not have this problem only the child ws server, aside from this setup I have not been able to reproduce this error myself.
Update:
I did run the child as a standalone process without starting it with amps process lib, the error remains I will report back if I find the reason.
Debugging works as expected when I run the websocket requests through my docker network proxy and dont use docker-compose port forwarding (but strangely this is not necessary for the ws master)
Anyway this seems to be a networking issue not related to amp so I will close this issue for now.