commit 33a54e79a1124a4fbbcc23789e1a32b12c6d621c
parent b6bb346b9350f3ebb61d186386f45b0b82a87de1
Author: Alexander Hansen Færøy <ahf@torproject.org>
Date: Wed, 11 Feb 2026 17:35:42 +0100
Merge branch 'fix/pt/relaunch/1' into 'main'
Fix: Don't launch managed proxies on impending shutdown
See merge request tpo/core/tor!985
Diffstat:
4 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/changes/pt-shutdown-fix b/changes/pt-shutdown-fix
@@ -0,0 +1,2 @@
+ o Minor feature (pluggable transports, shutdown):
+ - Don't launch managed proxies on impending shutdown
diff --git a/src/feature/client/transports.c b/src/feature/client/transports.c
@@ -97,6 +97,7 @@
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/or/circuitbuild.h"
+#include "feature/hibernate/hibernate.h"
#include "feature/client/transports.h"
#include "feature/relay/router.h"
#include "feature/relay/relay_find_addr.h"
@@ -530,6 +531,10 @@ proxy_prepare_for_restart(managed_proxy_t *mp)
/* destroy the process handle and terminate the process. */
if (mp->process) {
process_set_data(mp->process, NULL);
+ if (we_are_shutting_down())
+ log_notice(LD_CONFIG, "Managed proxy \"%s\" having PID %" PRIu64 " "
+ "is being terminated...", mp->argv[0],
+ process_get_pid(mp->process));
process_terminate(mp->process);
}
@@ -2144,9 +2149,13 @@ managed_proxy_exit_callback(process_t *process, process_exit_code_t exit_code)
managed_proxy_t *mp = process_get_data(process);
const char *name = mp ? mp->argv[0] : "N/A";
- log_warn(LD_PT,
- "Managed proxy \"%s\" process terminated with status code %" PRIu64,
- name, exit_code);
+ if (!we_are_shutting_down())
+ log_warn(LD_PT, "Managed proxy \"%s\" having PID %" PRIu64 " "
+ "terminated with status code %" PRIu64,
+ name, process_get_pid(process), exit_code);
+ else
+ log_notice(LD_PT, "Managed proxy \"%s\" having PID %" PRIu64 " "
+ "has exited.", name, process_get_pid(process));
if (mp) {
/* We remove this process_t from the mp. */
@@ -2156,8 +2165,10 @@ managed_proxy_exit_callback(process_t *process, process_exit_code_t exit_code)
/* Prepare the proxy for restart. */
proxy_prepare_for_restart(mp);
- /* We have proxies we want to restart? */
- pt_configure_remaining_proxies();
+ if (!we_are_shutting_down()) {
+ /* We have proxies we want to restart? */
+ pt_configure_remaining_proxies();
+ }
}
/* Returning true here means that the process subsystem will take care of
diff --git a/src/feature/hibernate/hibernate.c b/src/feature/hibernate/hibernate.c
@@ -930,6 +930,15 @@ hibernate_begin_shutdown(void)
}
/**
+ * Return true iff we are currently shutting down.
+ */
+MOCK_IMPL(int,
+we_are_shutting_down,(void))
+{
+ return hibernate_state == HIBERNATE_STATE_EXITING;
+}
+
+/**
* Return true iff we are currently hibernating -- that is, if we are in
* any non-live state.
*/
diff --git a/src/feature/hibernate/hibernate.h b/src/feature/hibernate/hibernate.h
@@ -24,6 +24,7 @@ void accounting_run_housekeeping(time_t now);
void accounting_add_bytes(size_t n_read, size_t n_written, int seconds);
int accounting_record_bandwidth_usage(time_t now, or_state_t *state);
void hibernate_begin_shutdown(void);
+MOCK_DECL(int, we_are_shutting_down, (void));
MOCK_DECL(int, we_are_hibernating, (void));
MOCK_DECL(int, we_are_fully_hibernating,(void));
void consider_hibernation(time_t now);