improved tunnel cleanup#706
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7784d73bc1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7784d73. Configure here.
|
|
||
| async def _cleanup(self) -> None: | ||
| """Clean up tunnel resources.""" | ||
| _active_tunnels.discard(self) |
There was a problem hiding this comment.
Premature discard defeats atexit backstop on cancellation
Low Severity
_active_tunnels.discard(self) at the top of _cleanup() removes the tunnel from the atexit tracking set before any actual cleanup runs. If the async cleanup is interrupted by CancelledError at an await point (e.g., delete_tunnel or client.close), the error escapes the except Exception handlers (since CancelledError is a BaseException), skipping remaining cleanup steps. Because the tunnel was already discarded, the atexit backstop in _stop_active_tunnels can never retry the incomplete cleanup — defeating its stated purpose of catching "forgotten cleanup" and "unhandled exception" scenarios. Moving the discard to the end of _cleanup() would let the atexit handler pick up partially-cleaned tunnels via sync_stop.
Reviewed by Cursor Bugbot for commit 7784d73. Configure here.


Note
Low Risk
Small defensive lifecycle change reusing existing sync_stop; atexit may run extra HTTP deletes on abrupt exit but does not alter normal start/stop behavior.
Overview
Adds an atexit backstop so tunnels that were started but never stopped still run cleanup when the process exits.
After a successful
start(), eachTunnelis tracked in a module-level_active_tunnelsset. On normal shutdown paths,sync_stopand_cleanupremove the instance from that set. At process exit,_stop_active_tunnelsiterates any remaining entries and callssync_stop()(errors ignored), which should tear down frpc, delete the backend registration, and remove the config file—reducing leaked registrations when cleanup is skipped due to crashes or forgottenstop().Reviewed by Cursor Bugbot for commit 7784d73. Bugbot is set up for automated code reviews on this repo. Configure here.