Hi,
I've forgotten to free the shmem, thus enclosed an amendment with clean-up, relative last changeset. Regards, sebres. 10.06.2015 21:48, Sergey Brester: > Hi, > > enclosed you will find an attached changeset, that contains fix for windows > issue with multiple workers (once listening - only one made any work). > > If someone needs a git version of it: > > https://github.com/sebres/nginx/pull/1/files [2] > > Here [3] you may find a benchmark comparison for that (1 worker column - > measured before fix). > > -- > > Shortly about fix algorithm (changes related are marked as [*], unchanged - > [-]): > > - master process create all listener; > > - [cycle] master process create a worker; > > * [win32] master calls `ngx_share_listening_sockets`: each listener share > (inheritance) info for pid of this worker ("cloned" via WSADuplicateSocket), > that will be saved in shmem; > > - master process wait until worker will send an event "worker_nnn"; > > * [win32] worker process executes `ngx_get_listening_share_info` to obtain > shared info, protocol structure that can be used to create a new socket > descriptor for a shared socket; > > * [win32] worker process creates all listener sockets using given shared info > of master; > > - worker process sets an event "worker_nnn"; > > - master process create next worker, repeat [cycle]. > > -- > > @Maxim Dounin: > 1) your suggested way with shared handle and bInheritHandle does not work, > because of: > [quote] > Sockets. No error is returned, but the duplicate handle may not be recognized > by Winsock at the target process. Also, using DUPLICATEHANDLE interferes with > internal reference counting on the underlying object. > To duplicate a socket handle, use the WSADUPLICATESOCKET function. > [/quote] > > 2) proposal to use an environment instead of shared memory can not work also, > because sharing via WSADuplicateSocket should already know a pid of target > process, that uses this handle - specially shared for each worker. > > BTW, using of `accept_mutex` was disallowed for win32, cause of possible > deadlock if grabbed by a process which can't accept connections. Because, > this is fixed now, I have removed this "restriction" in separated commit. > But I think, accept_mutex is not needed in win32 resp. with accept_mutex it > is much slower as without him. So, whats about set default of `accept_mutex` > to `off` on windows platform? > > BTW[2], I have executed extensive tests of this fix, also with reloading > (increase/decrease `worker_processes`), restarting, as well as > auto-restarting of worker, if it was "crashed" (ex.: have sporadically killed > some worker). > > Regards, > Serg G. Brester (aka sebres). > > _______________________________________________ > nginx-devel mailing list > nginx-devel@nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel [1] Links: ------ [1] http://mailman.nginx.org/mailman/listinfo/nginx-devel [2] https://github.com/sebres/nginx/pull/1/files [3] https://github.com/sebres/nginx/pull/1
# HG changeset patch # User sebres <serg.bres...@sebres.de> # Date 1434027119 -7200 # Thu Jun 11 14:51:59 2015 +0200 # Node ID 76ee2fe9300bdcf0dbf4a05e3ed7a1136b324eb7 # Parent e40ee60150e47616d86fdee90f62f0f88c4b1e80 clean-up amendment for windows issue with multiple workers: free shared memory for inherited protocol info; diff -r e40ee60150e4 -r 76ee2fe9300b src/core/ngx_connection.c --- a/src/core/ngx_connection.c Wed Jun 10 19:39:18 2015 +0200 +++ b/src/core/ngx_connection.c Thu Jun 11 14:51:59 2015 +0200 @@ -641,6 +641,12 @@ ngx_open_listening_sockets(ngx_cycle_t * return NGX_ERROR; } +#if (NGX_WIN32) + if (ngx_process > NGX_PROCESS_MASTER) { + ngx_free_listening_share(cycle); + } +#endif + return NGX_OK; } @@ -906,6 +912,10 @@ ngx_close_listening_sockets(ngx_cycle_t ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, "[%d] close %d listener(s)", ngx_process, cycle->listening.nelts); +#if (NGX_WIN32) + ngx_free_listening_share(cycle); +#endif + ngx_accept_mutex_held = 0; ngx_use_accept_mutex = 0; diff -r e40ee60150e4 -r 76ee2fe9300b src/os/win32/ngx_socket.c --- a/src/os/win32/ngx_socket.c Wed Jun 10 19:39:18 2015 +0200 +++ b/src/os/win32/ngx_socket.c Thu Jun 11 14:51:59 2015 +0200 @@ -79,6 +79,17 @@ ngx_int_t ngx_get_listening_share(ngx_cy } +void ngx_free_listening_share(ngx_cycle_t *cycle) +{ + if (shm_listener.addr) { + + ngx_shm_free(&shm_listener); + shm_listener.addr = NULL; + + } +} + + ngx_shared_socket_info ngx_get_listening_share_info(ngx_cycle_t *cycle, ngx_pid_t pid) { diff -r e40ee60150e4 -r 76ee2fe9300b src/os/win32/ngx_socket.h --- a/src/os/win32/ngx_socket.h Wed Jun 10 19:39:18 2015 +0200 +++ b/src/os/win32/ngx_socket.h Thu Jun 11 14:51:59 2015 +0200 @@ -211,6 +211,7 @@ typedef WSAPROTOCOL_INFO * ngx_shared_so ngx_shared_socket_info ngx_get_listening_share_info(ngx_cycle_t *cycle, ngx_pid_t pid); +void ngx_free_listening_share(ngx_cycle_t *cycle); ngx_int_t ngx_share_listening_sockets(ngx_cycle_t *cycle, ngx_pid_t pid);
_______________________________________________ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel