Skip to content

Commit a4bd1e5

Browse files
joamagclaude
andcommitted
feat(base): on_config hook + main-loop deferral for SIGHUP
Adds `on_config` as an overridable hook on `AbstractBase` so subclasses can react to `SIGHUP` reload signals; the inherited implementation fires the existing `"config"` trigger. The `bind_config` signal handler now defers `on_config` to the main event loop via `delay(immediately=True)` instead of running it synchronously in the signal-handler context, removing the reentrancy concern for subclass overrides. `ConsulProxyServer.on_config` is wired to schedule an extra `_consul_tick(timeout=0)` so operators can force a Consul service refresh on `SIGHUP` without waiting for the next poll cycle. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b7c908b commit a4bd1e5

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
*
12+
* `on_config` hook on `AbstractBase` that subclasses can override to react to `SIGHUP` reload signals (chains to the existing `"config"` trigger via super)
13+
* `ConsulProxyServer.on_config` override that schedules an extra `_consul_tick(timeout=0)` on `SIGHUP`, allowing operators to force a Consul service refresh without waiting for the next poll cycle
1314

1415
### Changed
1516

16-
*
17+
* `bind_config` SIGHUP handler now defers `on_config` to the main event loop via `delay(immediately=True)` instead of running it synchronously in the signal handler context, so subclass overrides don't have to worry about signal-handler reentrancy
1718

1819
### Fixed
1920

src/netius/base/common.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ def bind_config(
16931693
),
16941694
):
16951695
def base_handler(signum=None, frame=None):
1696-
self.trigger("config", self)
1696+
self.delay(lambda: self.on_config(), immediately=True)
16971697

16981698
for signum in signals:
16991699
if signum == None:
@@ -3100,6 +3100,9 @@ def on_pause(self):
31003100
def on_resume(self):
31013101
self.trigger("resume", self)
31023102

3103+
def on_config(self):
3104+
self.trigger("config", self)
3105+
31033106
def on_read(self, _socket):
31043107
# tries to retrieve a possible callback registered for the socket
31053108
# and if there's one calls it to be able to "append" extra operations

src/netius/extra/proxy_c.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ def on_serve(self):
113113
self.info("Consul poll interval set to %.2fs", self.consul_poll_interval)
114114
self._consul_tick(timeout=self.consul_poll_interval)
115115

116+
def on_config(self):
117+
proxy_r.ReverseProxyServer.on_config(self)
118+
self._consul_tick(timeout=0)
119+
116120
def _build_consul(self, entries):
117121
self._debug_entries(entries)
118122
self._build_hosts(entries)

0 commit comments

Comments
 (0)