Skip to content

Commit 7779bd6

Browse files
committed
[fix] fixed a crash bug resulted from 'reload' (#238).
1 parent e342d76 commit 7779bd6

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

.github/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
* **[misc]** if some changes were done and bugs were fixed.
2020

2121
* Ensure that your codes conform to code conventions:
22-
* All files are prefixed by 'ngx_'.
22+
* All files are prefixed by 'ngx\_'.
2323
* Include #ifndef \_FILE\_NAME\_H\_INCLUDED\_, #define \_FILE\_NAME\_H\_INCLUDED\_ and #endif in header files.
2424
* Comments use /* ... */ are preferable.
2525
* It would be better that built-in types appear before customized types.
2626
* There should be no less than 2 spaces between types and variables.
27-
* Variables are aligned by character, not '*'.
27+
* Variables are aligned by character, not '\*'.
2828
* No more than 80 characters in a single code or comment line.
2929
* Two blank lines between two functions, styles of macro and type definitions are same as functions.
3030

ngx_rtmp_auto_push_module.c

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ ngx_rtmp_auto_push_init_process(ngx_cycle_t *cycle)
133133
struct sockaddr_un *saun;
134134
#if (nginx_version >= 1009011)
135135
ngx_event_t *rev;
136-
ngx_connection_t *c, *old;
136+
ngx_connection_t *c;
137137
ngx_module_t **modules;
138138
ngx_int_t i, auto_push_index, event_core_index;
139139
#endif
@@ -310,26 +310,6 @@ ngx_rtmp_auto_push_init_process(ngx_cycle_t *cycle)
310310
rev->deferred_accept = ls->deferred_accept;
311311
#endif
312312

313-
if (!(ngx_event_flags & NGX_USE_IOCP_EVENT)) {
314-
if (ls->previous) {
315-
316-
/*
317-
* delete the old accept events that were bound to
318-
* the old cycle read events array
319-
*/
320-
321-
old = ls->previous->connection;
322-
323-
if (ngx_del_event(old->read, NGX_READ_EVENT, NGX_CLOSE_EVENT)
324-
== NGX_ERROR)
325-
{
326-
return NGX_ERROR;
327-
}
328-
329-
old->fd = (ngx_socket_t) -1;
330-
}
331-
}
332-
333313
#if (nginx_version >= 1009013)
334314
rev->handler = (c->type == SOCK_STREAM) ? ngx_event_accept
335315
: ngx_event_recvmsg;
@@ -369,11 +349,55 @@ ngx_rtmp_auto_push_exit_process(ngx_cycle_t *cycle)
369349
ngx_rtmp_auto_push_conf_t *apcf;
370350
u_char path[NGX_MAX_PATH];
371351

352+
ngx_listening_t *ls;
353+
ngx_connection_t *c;
354+
size_t n;
355+
372356
apcf = (ngx_rtmp_auto_push_conf_t *) ngx_get_conf(cycle->conf_ctx,
373357
ngx_rtmp_auto_push_module);
374358
if (apcf->auto_push == 0) {
375359
return;
376360
}
361+
362+
ls = cycle->listening.elts;
363+
364+
for (n = 0; n < cycle->listening.nelts; ++n, ++ls) {
365+
if ((ls->handler == ngx_rtmp_init_connection) &&
366+
(ls->sockaddr && ls->sockaddr->sa_family == AF_UNIX))
367+
{
368+
c = ls->connection;
369+
370+
if (c) {
371+
if (c->read->active) {
372+
if (!(ngx_event_flags & NGX_USE_IOCP_EVENT)) {
373+
374+
/*
375+
* delete the old accept events that were bound to
376+
* the old cycle read events array
377+
*/
378+
379+
ngx_del_event(c->read,
380+
NGX_READ_EVENT, NGX_CLOSE_EVENT);
381+
382+
ngx_free_connection(c);
383+
384+
c->fd = (ngx_socket_t) -1;
385+
}
386+
}
387+
}
388+
389+
if (ngx_close_socket(ls->fd) == -1) {
390+
ngx_log_error(NGX_LOG_ERR, cycle->log, ngx_socket_errno,
391+
ngx_close_socket_n "%V failed",
392+
&ls->addr_text);
393+
}
394+
395+
ls->fd = (ngx_socket_t) -1;
396+
397+
break;
398+
}
399+
}
400+
377401
*ngx_snprintf(path, sizeof(path),
378402
"%V/" NGX_RTMP_AUTO_PUSH_SOCKNAME ".%i",
379403
&apcf->socket_dir, ngx_process_slot)

0 commit comments

Comments
 (0)