Skip to content

fix: log actionable error when the server cannot bind its port - #243

Open
scottsgevor wants to merge 1 commit into
ActivityWatch:masterfrom
scottsgevor:fix/log-bind-failure
Open

scottsgevor wants to merge 1 commit into
ActivityWatch:masterfrom
scottsgevor:fix/log-bind-failure

Conversation

@scottsgevor

@scottsgevor scottsgevor commented Dec 2, 2026 •

Copy link
Copy Markdown

Problem

When the server cannot bind its port, werkzeug prints the error to stderr and calls sys.exit(1). aw-qt starts modules without a console and deliberately does not pipe stdout/stderr (#27), so the message is lost: the module log stops at Using database file… and the tray only reports "Module aw-server crashed and was auto-restarted".

On Windows this commonly happens when Hyper-V/WSL has reserved a port range that includes 5600 (WinError 10013), see ActivityWatch/activitywatch#571. The existing except OSError in _start() never fires because werkzeug exits via SystemExit.

Change

Catch SystemExit around app.run(). For a non-zero exit code, log the address that failed to bind and the likely causes. On Windows, include the Hyper-V/WSL hint and the netsh commands that reserve the port for ActivityWatch. The exception is re-raised, so the exit code is unchanged.

The aw-qt crash dialog already shows the module log, so the reason becomes visible without any aw-qt change. A companion aw-qt PR adds a dedicated dialog for this case.

Companion PR: ActivityWatch/aw-qt#164

Test

  • Added tests/test_server.py::test_start_logs_bind_failure, which simulates werkzeug's SystemExit(1) and asserts that it propagates and that the log contains the address.
  • pytest tests/test_server.py: 58 passed.
  • ruff check / black --check on the changed files: clean.

Refs ActivityWatch/activitywatch#571

werkzeug reports bind failures by printing to stderr and calling
sys.exit(1), which is invisible when aw-qt spawns modules without a
console. Catch the SystemExit and log the likely cause (including the
Windows Hyper-V/WSL port-reservation hint) so the reason reaches the
module log and the aw-qt crash dialog.
@greptile-apps

greptile-apps Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Low impact] The PR appears safe to merge.

Summary

Adds a logged explanation when app.run() raises a nonzero SystemExit.

  • Server startup logs the reason when its port cannot be bound.

No actionable issues found. Tests were not run during this review.

Reviews (1) · Last reviewed commit: "fix: log actionable error when the serve..." · Reviewed by Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant