Skip to content

Commit 4839b17

Browse files
committed
upgrade to handle handle zero downtime app load and unload for different app path
1 parent 96f96c5 commit 4839b17

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

src/ngx_http_c_func_module.c

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -691,46 +691,53 @@ ngx_http_c_func_process_exit(ngx_cycle_t *cycle) {
691691
new_ctx.shared_mem = (void*)mcf->shm_ctx->shared_mem;
692692
func(&new_ctx);
693693
}
694-
} else {
695-
continue;
696-
}
697-
}
698-
}
699-
700-
static void
701-
ngx_http_c_func_master_exit(ngx_cycle_t *cycle) {
702-
ngx_uint_t s;
703-
ngx_http_c_func_srv_conf_t *scf;
704-
ngx_http_core_srv_conf_t **cscfp;
705-
ngx_http_core_main_conf_t *cmcf;
706-
ngx_http_c_func_main_conf_t *cfunmcf;
707-
ngx_http_conf_ctx_t *ctx = (ngx_http_conf_ctx_t *)ngx_get_conf(cycle->conf_ctx, ngx_http_module);
708-
709-
cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
710-
cscfp = cmcf->servers.elts;
711-
712-
for (s = 0; s < cmcf->servers.nelts; s++) {
713-
ngx_http_core_srv_conf_t *cscf = cscfp[s];
714-
scf = cscf->ctx->srv_conf[ngx_http_c_func_module.ctx_index];
715-
if (scf && scf->_app ) {
694+
// Unload app, unload old app if nginx reload
716695
if (dlclose(scf->_app) != 0) {
717696
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "Error to unload the app lib %V", &scf->_libname);
718697
} else {
719-
ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "Unloaded app lib %V", &scf->_libname);
698+
ngx_log_error(NGX_LOG_DEBUG, cycle->log, 0, "Unloaded app lib %V", &scf->_libname);
720699
}
721-
722700
} else {
723701
continue;
724702
}
725703
}
704+
}
726705

727-
cfunmcf = ctx->main_conf[ngx_http_c_func_module.ctx_index];
706+
static void
707+
ngx_http_c_func_master_exit(ngx_cycle_t *cycle) {
708+
// Bug Fixed Migrate dlclose to process exit cycle to handling nginx reload
709+
// ngx_uint_t s;
710+
// ngx_http_c_func_srv_conf_t *scf;
711+
// ngx_http_core_srv_conf_t **cscfp;
712+
// ngx_http_core_main_conf_t *cmcf;
713+
// ngx_http_c_func_main_conf_t *cfunmcf;
714+
// ngx_http_conf_ctx_t *ctx = (ngx_http_conf_ctx_t *)ngx_get_conf(cycle->conf_ctx, ngx_http_module);
715+
716+
// cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
717+
// cscfp = cmcf->servers.elts;
718+
719+
// for (s = 0; s < cmcf->servers.nelts; s++) {
720+
// ngx_http_core_srv_conf_t *cscf = cscfp[s];
721+
// scf = cscf->ctx->srv_conf[ngx_http_c_func_module.ctx_index];
722+
// if (scf && scf->_app ) {
723+
// if (dlclose(scf->_app) != 0) {
724+
// ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "Error to unload the app lib %V", &scf->_libname);
725+
// } else {
726+
// ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "Unloaded app lib %V", &scf->_libname);
727+
// }
728+
729+
// } else {
730+
// continue;
731+
// }
732+
// }
728733

729-
if (cfunmcf == NULL) {
730-
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "Error when master exit");
731-
return;
732-
}
734+
// cfunmcf = ctx->main_conf[ngx_http_c_func_module.ctx_index];
733735

736+
// if (cfunmcf == NULL) {
737+
// ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "Error when master exit");
738+
// return;
739+
// }
740+
// End Bug Fixed Migrate dlclose to process exit cycle to handling nginx reload
734741

735742
// if (cfunmcf->shm_ctx && cfunmcf->shm_ctx->shared_mem) {
736743
// if (cfunmcf->shm_ctx->shared_mem->shpool && cfunmcf->shm_ctx->shared_mem->shpool->log_ctx) {

0 commit comments

Comments
 (0)