Repository navigation
fix(tray): report unavailable server ports instead of restart loops - #164
Open
scottsgevor wants to merge 3 commits into
Open
scottsgevor wants to merge 3 commits into
scottsgevor wants to merge 3 commits into
Conversation
When a server module exits and its port cannot be bound, explain the actual cause (in use / blocked by Windows) in a dialog and stop the pointless auto-restart loop. The probe mirrors the server's SO_REUSEADDR bind to avoid false positives from TIME_WAIT sockets.
Contributor
Confidence Score: 5/5
[Medium impact] The PR appears safe to merge; no blocking issues remain. SummaryThe PR reports unavailable server ports instead of repeatedly restarting the server.
Reviews (3) · Last reviewed commit: "fix(tray): keep port probe errors from e..." · Reviewed by Greptile |
- Check for an existing listener with connect_ex before binding: on Windows SO_REUSEADDR can make a bind-over succeed, which made the probe miss a port that is already in use. - Add listen() to the bind probe so it tests whether the server can actually listen, not just bind. - Read the configured host from aw-server.toml / aw-server-rust config.toml and probe with the matching address family, so an unrelated IPv4 listener no longer blocks IPv6 recovery (and IPv6 conflicts are detected). - Update tests with real listeners, IPv6 cases, and host/address resolution.
Author
|
Addressed both Greptile findings in 9005482:
Local on Windows: 377 passed, 16 skipped (3 pre-existing Linux-only autostart failures, unrelated). |
Author
|
@greptileai review |
socket() can fail before the probe's try block (e.g. an unavailable IPv6 stack on a ::1 config). Catch creation errors in bind_error and return them like bind failures, so the tray shows the dialog and keeps its status timer running instead of raising out of the Qt callback.
Author
|
Fixed in 0bc70e7: @greptileai review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
If
aw-server(oraw-server-rust) cannot bind its port, the process exits immediately and the tray only reports "Module aw-server crashed and was auto-restarted" three times before giving up. The actual reason is invisible: the server writes its bind error to stderr, which aw-qt intentionally does not capture (ActivityWatch/aw-server#27).This is most visible on Windows when Hyper-V/WSL reserves the port (
WinError 10013, see ActivityWatch/activitywatch#571), but it also happens when another process holds the port.Change
aw_qt/serverport.py:bind_error()first checks for an existing listener withconnect_ex: on WindowsSO_REUSEADDRcan let a bind-over succeed, so a bind test alone can miss an occupied port. It then binds withSO_REUSEADDRand callslisten(), matching the servers' own setup (werkzeug setsallow_reuse_address) and avoiding false positives from TIME_WAIT sockets.aw-server.toml/ aw-server-rustconfig.toml) and the matching address family, so IPv6 binds (::1) and IPv4-only conflicts are handled correctly.describe_bind_error()explains the cause: Windows 10013 gets the Hyper-V/WSL explanation plus thenetshcommands;EADDRINUSEreports another program using the port.TrayIconchecks server modules before auto-restarting. If the port is unavailable it shows a dedicated dialog ({module} can't start: {host}:{port} is unavailable, the cause, and the full module log under Details, with a Restart button), stops the module and skips the restart loop.Module.get_server_address()exposes the configured (host, port); the host is read alongside the existing port lookup.Test
tests/test_serverport.py: free port, a real open listener, an IPv6 listener, an IPv4 listener that must not block the IPv6 probe, bind failure, and both message variants.tests/test_tray_status.py: an unavailable port shows the dialog and does not restart; an available port keeps the existing auto-restart path.tests/test_manager.py.flake8reports no new warnings.Companion PR: ActivityWatch/aw-server#243
Refs ActivityWatch/activitywatch#571