Skip to content

Fall back to a free port when the view's default port is taken - #279

Merged
yourconscience merged 1 commit into
mainfrom
view-port-fallback
Nov 16, 2026
Merged

yourconscience merged 1 commit into
mainfrom
view-port-fallback

Conversation

@yourconscience

@yourconscience yourconscience commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

tackroom view listens on 127.0.0.1:8765 by default and failed with address already in use when another program held that port.

Without --addr, it now tries the address the last view recorded, then any free port on the same host, says which address it serves on and prints that URL. The recorded address comes first so a view restarted after an upgrade keeps the URL an open tab already has. An explicit --addr that is taken is still an error.

Checked with the built binary in a clean home while another program held 8765:

  • first run serves on a free port and its start URL answers 303;
  • a second run finds the first and starts nothing;
  • after a restart the view comes back on the same port;
  • --addr 127.0.0.1:8765 exits 1 with the bind error.

Not exercised: the default port being free, which is the unchanged first net.Listen.

Summary by Sourcery

Keep the view available by reusing its recorded loopback address or selecting a free port when the default is occupied.

New Features:

  • Allow tackroom view to fall back to a free loopback port when the default port is unavailable and no explicit address was provided.
  • Prefer the previously recorded view address so restarts can preserve an existing URL.

Bug Fixes:

  • Prevent default view startup from failing when another program is already using the default port.

Enhancements:

  • Report the fallback serving address and clarify fallback and explicit-address behavior in the view documentation.

Documentation:

  • Document automatic port fallback, address reuse, and explicit-address errors for tackroom view.

Summary by CodeRabbit

  • New Features
    • When the default port is occupied and no address is specified, view now tries a previously used free address or selects another available port, then reports the URL.
    • Subsequent runs reuse the recorded port while it remains available.
  • Bug Fixes
    • An occupied address explicitly supplied with --addr is reported as an error rather than silently switching ports.
  • Documentation
    • Updated --addr guidance to describe automatic port selection and reuse.

@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Sorry @yourconscience, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 4 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@yourconscience

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

When binding fails for the default address, view tries a recorded valid loopback address, then a free port on the same host. An explicitly specified address does not use this fallback. The documentation describes port selection, reporting, and reuse.

Changes: View address fallback

Layer / File(s) Summary
Fallback address selection and reporting
internal/app/config_web.go, docs/view.md
runConfigServe invokes fallback binding only when --addr was not explicitly set. The fallback tries a recorded valid loopback address, then a free port on the same host. If no candidate binds, it returns the original listen error. The documentation describes the default and explicit address behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant runConfigServe
  participant listenFallback
  participant recordedViewAddr
  participant Listener
  runConfigServe->>listenFallback: Pass address and original listen error
  listenFallback->>recordedViewAddr: Check recorded address
  recordedViewAddr-->>listenFallback: Return valid loopback address or empty
  listenFallback->>Listener: Try recorded address, then free port on same host
  Listener-->>listenFallback: Return listener or bind error
  listenFallback-->>runConfigServe: Return listener or original listen error
Loading
Merge Risk: Low · up to d6492

When the default port becomes free again, restarting tackroom view may serve on the default port instead of the previously recorded fallback port. Bookmarks or proxies pointing at the fallback port would then stop working. This is a narrow, recoverable inconsistency with the documented behavior, so the change is mergeable with owner awareness.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sourcery-ai

sourcery-ai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

When the default bind fails, the view tries its previously recorded address and then a free port, while running-view discovery also checks that recorded address.

  • internal/app/config_web.go L70-72, L101-102, L125-162

Documentation

Document the fallback behavior, port reuse, and the error for an occupied explicitly supplied address.

  • docs/view.md L16

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Action not completed

Pull request is closed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@yourconscience
yourconscience merged commit c26a277 into main Nov 16, 2026
12 of 13 checks passed
@yourconscience
yourconscience deleted the view-port-fallback branch November 16, 2026 08:32
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