Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically use a different port if port 8080 is in use #1945

Closed
ChocolateLoverRaj opened this issue Feb 16, 2024 · 5 comments
Closed

Automatically use a different port if port 8080 is in use #1945

ChocolateLoverRaj opened this issue Feb 16, 2024 · 5 comments
Assignees
Labels
cli Related to the dioxus-cli program enhancement New feature or request
Milestone

Comments

@ChocolateLoverRaj
Copy link

Specific Demand

If there's already another http server using port 8080, running dx serve (on the Web app) fails:

Dioxus @ v0.4.1 [20:24:14] 

        > Local : http://localhost:8080/
        > Network : http://192.168.1.3:8080/
        > HTTPS : Disabled

        > Profile : Debug
        > Hot Reload : Normal
        > Index Template : Default
        > URL Rewrite [index_on_404] : True

        > Build Time Use : 63658 millis

[INFO] A perfect compilation!

thread 'main' panicked at /var/home/rajas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.28/src/server/server.rs:81:13:
error binding to 0.0.0.0:8080: error creating server listener: Address already in use (os error 98)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Implement Suggestion

If 8080 isn't available, try using 8081. If that's not available, use 8082, etc. I'm pretty sure Webpack does this and it's convenient.

@ealmloff ealmloff added cli Related to the dioxus-cli program enhancement New feature or request labels Feb 16, 2024
@alexanderjophus
Copy link
Contributor

I'm looking at implementing this, but I have some questions.

There's a few ways ports can be selected.

  • The user specifically requests port 9000 for example, in my opinion this should fail if port 9000 is already taken.
  • The user does not specify a port 8080 is taken be default, in my opinion this is where dioxus could look into other open ports.
  • The user specifies port 0, this means the OS allocates a free open port.

Right now what happens is the browser (if the option is chosen) is opened on the port, then the server begins. This change would have to start the server first, then open the browser on the port chosen (especially in the case of port 0).

@LiamKarlMitchell
Copy link
Contributor

Improving the error message to suggest that --port can be used to start on a different port if needed would be nice.

@jkelleyrtp
Copy link
Member

jkelleyrtp commented Nov 2, 2024

We now have a better error:

    0: Failed to bind server to: 127.0.0.1:8080, is there another devserver running?
       To run multiple devservers, use the --port flag to specify a different port
    1: Address already in use (os error 48)

@ChocolateLoverRaj
Copy link
Author

It's a better error than before, but it doesn't change the motivation behind this issue.

@jkelleyrtp
Copy link
Member

Coming soon in 0.6.2 thanks to #3586

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the dioxus-cli program enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants