[PATCH] Fixed state protection when restarting during the websocket request process

Maxim Dounin mdounin at mdounin.ru
Tue Dec 20 08:03:39 UTC 2022


On Tue, Dec 20, 2022 at 03:01:59PM +0800, 乔志奇 wrote:

> # HG changeset patch
> # User 乔志奇@Matebook-Qiao <qiaozhiqi2016 at gmail.com>
> # Date 1671515941 -28800
> #      Tue Dec 20 13:59:01 2022 +0800
> # Branch nginx-bugfix-websocket
> # Node ID 3e68435db4a9991921b5bf91d792787a1ad387fb
> # Parent  3108d4d668e4b907868b815f0441d4c893bf4188
> Fixed state protection when restarting during the websocket request process
> During the websocket request process, it is necessary to add a timer
> operation, but we need to do state protection for the timer addition
> operation. When the nginx process is restarted or stopped, the timer should
> be prohibited from being added, otherwise continuous websocket requests
> will cause the old process to be unable to exit during the restart process
> or unable to exit during the stop process.

Thanks, but no.

The graceful exit process is expected to handle all existing 
connections till they are closed normally.  This includes 
Websocket connections.

The recommended approach for long-running connections (including 
Websocket, stream module connections, or just long-running HTTP 
requests) is to close them periodically from the server side, so 
they can be properly re-established without errors.

If this does not work for you for some reason (for example, if you 
cannot control the behaviour of the backend server), consider 
using the "worker_shutdown_timeout" directive
(http://nginx.org/r/worker_shutdown_timeout) to terminate all 
connections after certain period of time. 

Maxim Dounin

More information about the nginx-devel mailing list