Ratchet icon indicating copy to clipboard operation
Ratchet copied to clipboard

Graceful stop is not possible with enableKeepAlive

Open kaero598 opened this issue 5 years ago • 4 comments

Hi.

As much as I have seen throughout examples and issue comments, the only advertised way to stop running server is to call EventLoop::stop(). I agree that it's a perfectly viable solution, however ReactPHP docs state that usage of this method is not recommended to stop the loop, and there are projects that rely on automatic loop termination istead.

The problem I encountered is that enableKeepAlive() created periodic timer that is never ever cancelled, resulting in websocket server never terminating without call to EventLoop::stop() (which I do not rely on).

I would suggest adding another method that would disable keep-alive and cancel periodic timer.

A workaround I use is to create a timer with 0.1 second timeout that would call EventLoop::stop(). But this is not as alegant as it could be.

kaero598 avatar Aug 18 '19 16:08 kaero598

What's the use case you'd want stop a running WebSocket server without ending the Unix process?

cboden avatar May 28 '20 15:05 cboden

The use case is running asynchronous pre-terminate tasks after websocket server has stopped listening for incoming connection.

kaero598 avatar May 29 '20 06:05 kaero598

I'm thinking if we return the timer object from enableKeepAlive you could then call cancelTimer with it. Would that work for you?

cboden avatar Sep 17 '20 14:09 cboden

That certainly would work.

kaero598 avatar Sep 18 '20 07:09 kaero598