DioxusLabs / dioxus

Fullstack app framework for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
21.44k stars 826 forks source link

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

Open ChocolateLoverRaj opened 8 months ago

ChocolateLoverRaj commented 8 months ago

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.

alexanderjophus commented 8 months ago

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

There's a few ways ports can be selected.

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 commented 4 months ago

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

jkelleyrtp commented 1 week ago

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 commented 1 week ago

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