Skip to content

Feature Request: redbean auto-search for an available port if no port is provided. #1450

@pendashteh

Description

@pendashteh

Prerequisites

  • I am running the latest code. Mention the version if possible as well.
  • I carefully followed the README.md.
  • I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
  • I reviewed the Discussions, and have a new and useful enhancement to share.

Feature Description

Currently, on the first run of redbean, with no extra arguments provided, if the port 8080 is busy on the machine (which is not as unsual on a dev machine), there is an exit with a convoluted message that may mislead first-time users to assume it fails to run:

$ ./redbean-latest.com 
F2025-11-15T19:28:04.931764:tool/net/redbean.c:7037:redbean-latest:1009215] (srvr) bind error: Address already in use: 127.0.0.1:8080
error:tool/net/redbean.c:7037: exiting due to aforementioned error (host pop-os pid 1009215 tid 1009215)

Proposed is that, instead, when no argument is provided, redbean would search for an available port, starting from 8080, and utilise the first available port. This way, the simple run of a command is more likely to yield a result, which satisfies those who are trying out the software and still allows intentional users to specify port 8080 for consistency.

$ ./redbean-alpha.com 
(runs on port 8082 because port 8080 and 8081 were busy)
$ ./redbean-alpha.com -p 8080
(fails as expected because port 8080 is busy)

Motivation

Currently, first-time users may leave with the wrong impression that the build of redbean doesn't work on their machine. This feature easily mitigates that.

Also, while allowing intentional use to explicitly specify port 8080, in other cases, users can freely run redbean without worrying about port conflict knowing that it will automatically find and utilise an available port.

Possible Implementation

This can be implemented by replacing current behaviour near where the error message occurs (line 7036)

  if (!ports.n) {  // If using default port
    ProgramPort(8080);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions