Skip to content

Commit 3479ac4

Browse files
committed
zcore: fix use-after-free on shutdown
rpc_parser needs to be ordered after service(mysql_adaptor), otherwise on shutdown, the mysql objects are gone while rpc_parser still uses them.
1 parent 8515f82 commit 3479ac4

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

exch/zcore/main.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,6 @@ int main(int argc, char **argv)
405405
int ping_interval = pconfig->get_ll("mailbox_ping_interval");
406406
HX_unit_seconds(temp_buff, std::size(temp_buff), ping_interval, 0);
407407
mlog(LV_INFO, "system: mailbox ping interval is %s", temp_buff);
408-
409-
zserver_init(table_size, cache_interval, ping_interval);
410-
auto cl_7 = make_scope_exit(zserver_stop);
411-
exmdb_client_init(proxy_num, stub_num);
412-
auto cl_8 = make_scope_exit(exmdb_client_stop);
413-
rpc_parser_init(threads_num);
414-
auto cl_6 = make_scope_exit(rpc_parser_stop);
415408

416409
if (service_run_early() != 0) {
417410
mlog(LV_ERR, "system: failed to run PLUGIN_EARLY_INIT");
@@ -431,6 +424,15 @@ int main(int argc, char **argv)
431424
mlog(LV_ERR, "system: failed to start system services");
432425
return EXIT_FAILURE;
433426
}
427+
428+
zserver_init(table_size, cache_interval, ping_interval);
429+
auto cl_7 = make_scope_exit(zserver_stop);
430+
exmdb_client_init(proxy_num, stub_num);
431+
auto cl_8 = make_scope_exit(exmdb_client_stop);
432+
/* parser after zserver: dependency on session table */
433+
/* parser after service: dependency on mysql_adaptor */
434+
rpc_parser_init(threads_num);
435+
auto cl_6 = make_scope_exit(rpc_parser_stop);
434436
listener_init();
435437
auto cl_10 = make_scope_exit(listener_stop);
436438
if (listener_run(g_config_file->get_value("zcore_listen")) != 0) {

0 commit comments

Comments
 (0)