1. High-Level Summary (TL;DR)
- Impact: Medium - Enhances client resilience by allowing hot-reloading of the
server_urlwithout restarting the tunnel process. - Key Changes:
- Moved
server_base_urlfrom the staticTunnelstruct to the dynamically reloadableHotClientConfig. - Updated the configuration watcher to detect changes to the server URL and trigger a tunnel reconnect.
- Modified the SSE read loop and HTTP POST methods to fetch the latest server URL dynamically.
- Added a comprehensive integration test to verify the reconnect behavior upon URL changes.
- Moved
2. Visual Overview (Code & Logic Map)
3. Detailed Change Analysis
Hot Configuration Reloading
- Component Name:
config_watcher_client(Source:src/reload.rs) - What Changed: Added
server_base_urlto theHotClientConfigstruct so it can be safely swapped at runtime. The config watcher now checks if the new server URL differs from the currently loaded one. If a change is detected, it flags a reconnect (needs_reconnect = true) and updates the in-memory configuration.
Tunnel Connection Logic
- Component Name:
Tunnel(Source:src/tunnel.rs) - What Changed: The
Tunnelstruct no longer holds a staticserver_base_url. Instead, network methods likesse_read_loop()andtry_post()dynamically load the latest URL viaself.hot.load().server_base_url. This guarantees that if the config file is updated mid-session, new connections will point to the newly specified server.
Structural Refactoring
| Original Location | New Location | Reason |
|---|---|---|
Tunnel struct
| HotClientConfig struct
| Enables dynamic hot-reloading of the target server URL without recreating the entire tunnel object. |
Integration Testing
- Component Name:
reconnect_on_url_change.rs - What Changed: Introduced a new integration test suite. This test verifies the end-to-end hot-reload scenario:
- Starts Server A and Client connecting to A.
- Starts Server B.
- Rewrites the client's configuration file to point to Server B.
- Asserts that the client detects the change, logs the reconnection, and successfully routes traffic to Server B.
4. Impact & Risk Assessment
- Breaking Changes: None. This is a purely additive resilience feature.
- Testing Suggestions:
- Verify the hot-reload behavior in a staging environment by changing the
server_urlin the configuration file while active traffic is flowing. - Check for potential memory leaks or hanging connections if the previous SSE stream is not cleanly closed during the reconnect phase.
- Verify the hot-reload behavior in a staging environment by changing the