rust-lang / rust-lang/mdBook

Cannot use serve --open with --port 0

Open
#2,599 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug Command-serve
Dominant language
Rust
Stars
22.2k
Forks
1.9k
PR merge metrics
PR metrics pending

Description

Problem

When using the mdbook serve command with --port 0 and --open options, the opened page is wrong, as the port is 0 instead of the random port attributed by the system.

Image

Steps
  1. mdbook init abc --force
  2. mdbook serve abc --port 0 --open
Possible Solution(s)

The serving_url should contain the bound port instead of the asked port (0)

https://github.com/rust-lang/mdBook/blob/3a8faba6451d4513b059a5711829b7da10ddcfdc/src/cmd/serve.rs#L92

Maybe using something like bind_ephemeral could be used. It would maybe require to move the creation of the warp server in a separate function run before the thread spawn.

https://github.com/rust-lang/mdBook/blob/3a8faba6451d4513b059a5711829b7da10ddcfdc/src/cmd/serve.rs#L88-L90

Notes

No response

Version
mdbook v0.4.47

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/cmd/serve.rs around lines 88-92 and trace how the Warp server is created, spawned, and used to build serving_url. Investigate bind_ephemeral as suggested, then verify that mdbook serve abc --port 0 --open opens the randomly assigned bound port rather than port 0.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.