Reload the configuration atomically

A reload reads the file into a new configuration, allocated from the
defaults, and prepares its services without starting them. Only if the
whole file is read without an error does it come into force: the old
configuration's services stop accepting, the new ones start. On an
error everything prepared is dropped and the old configuration, which
never stopped, stays in force.

Each service holds its configuration until it is freed, after its last
client; a configuration no longer in force is released when the last
holder lets go (confhold/confput). freeconf() now only releases what a
configuration holds, touching nothing global.

What runs without a service of its own reads the configuration in
force, runconf, rather than conf, which a reload points at the one
being read: the resolver, which holds it while it waits (a client
resolves with its own service's), the log, the thread pool, the admin
pages, which walk the services under config_mutex, and the signal
handlers.

The users table, havelog and the resolver choice are per configuration
now, the resolver applied when the configuration comes into force, so
a refused file leaves the users as they were. The log file, the
configuration file name, the string table, daemon mode and the filter
list belong to the process and are handed from one configuration to
the next. Settings left out of a new file go back to their defaults,
where before they kept the old values.

The gap between the old and the new listening sockets remains: a
connection queued on an old service's socket when it closes is reset.
Handing the socket over is the next phase.

A test case reloads a broken file (nothing changes, alice still gets
in, bob from the refused file does not) and a good one (bob only, the
service on its new port, the old one closed, a download through the
old service finishing whole). 40 reloads, a third refused, under load
show no memory errors under AddressSanitizer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladimir DubrovinandClaude Opus 5.5 committed 2026-10-14 20:15:14 +03:00
1 parent 796e9f8156
commit 21ba6e9d0c
14 files changed
+399 -112

No files matched your search

+9 -5
View File
@@ -73,13 +73,13 @@ void __stdcall CommandHandler( DWORD dwCommand )
case SERVICE_CONTROL_SHUTDOWN:
SetStatus( SERVICE_STOP_PENDING, 0, 1 );
timetoexit = 1;
conf->paused++;
runconf->paused++;
/* ServiceMain() reports the service stopped once cyclestep() has
seen this and the services are done */
break;
case SERVICE_CONTROL_PAUSE:
SetStatus( SERVICE_PAUSE_PENDING, 0, 1 );
conf->paused++;
runconf->paused++;
SetStatus( SERVICE_PAUSED, 0, 0 );
break;
case SERVICE_CONTROL_CONTINUE:
@@ -120,9 +120,11 @@ void mysigusr1 (int sig){
int even = 0;
/* Signals may come while a reload reads the file: they act on the
configuration in force. */
void mysigpause (int sig){
conf->paused++;
runconf->paused++;
even = !even;
if(!even){
needreload = 1;
@@ -130,7 +132,7 @@ void mysigpause (int sig){
}
void mysigterm (int sig){
conf->paused++;
runconf->paused++;
timetoexit = 1;
}
@@ -554,6 +556,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
nsopen(); /* before a chroot in the configuration takes /proc away */
#endif
_3proxy_mutex_init(&config_mutex);
_3proxy_mutex_init(&confref_mutex);
_3proxy_mutex_init(&runningservices_mutex);
_3proxy_mutex_init(&bandlim_mutex);
_3proxy_mutex_init(&connlim_mutex);
@@ -581,10 +584,11 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
httpsrv_init();
#endif
freeconf(conf);
confbegin();
initcommands();
res = readconfig(fp);
conf->version++;
resolvfunc = conf->resolvfunc;
/* readconfig() names the failing line, which an exit status would cut
to 8 bits: a failed configuration exits with 1 */