commit f79afc54dd5cd2c6388dc535e91b002a9495b572
parent dd25a8c7de4d680ae7333dd5d6863c10f20b2e54
Author: Waldemar Zimpel <w.zimpel@dev.utilizer.de>
Date: Thu, 27 Mar 2025 23:15:05 +0100
Fix: Crash on SIGSEGV if at least one worker thread cannot be launched
Perform a clean shutdown in case worker threads cannot be lauched.
Diffstat:
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/app/main/main.c b/src/app/main/main.c
@@ -1244,7 +1244,8 @@ run_tor_main_loop(void)
/* launch cpuworkers. Need to do this *after* we've read the onion key. */
/* launch them always for all tors, now that clients can solve onion PoWs. */
- cpuworker_init();
+ if (cpuworker_init() == -1)
+ return -1;
consdiffmgr_enable_background_compression();
diff --git a/src/core/mainloop/cpuworker.c b/src/core/mainloop/cpuworker.c
@@ -113,10 +113,8 @@ cpuworker_consensus_has_changed(const networkstatus_t *ns)
set_max_pending_tasks(ns);
}
-/** Initialize the cpuworker subsystem. It is OK to call this more than once
- * during Tor's lifetime.
- */
-void
+/** Initialize the cpuworker subsystem. */
+int
cpuworker_init(void)
{
/*
@@ -132,11 +130,18 @@ cpuworker_init(void)
worker_state_free_void,
NULL);
+ if (!threadpool) {
+ log_err(LD_GENERAL, "Can't create worker thread pool");
+ return -1;
+ }
+
int r = threadpool_register_reply_event(threadpool, NULL);
tor_assert(r == 0);
set_max_pending_tasks(NULL);
+
+ return 0;
}
/** Free all resources allocated by cpuworker. */
diff --git a/src/core/mainloop/cpuworker.h b/src/core/mainloop/cpuworker.h
@@ -12,7 +12,7 @@
#ifndef TOR_CPUWORKER_H
#define TOR_CPUWORKER_H
-void cpuworker_init(void);
+int cpuworker_init(void);
void cpuworker_free_all(void);
void cpuworkers_rotate_keyinfo(void);