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

IPFS has errored, because 8080 is already in use #912

Closed
PaulCombal opened this issue Apr 22, 2019 · 12 comments · Fixed by #989
Closed

IPFS has errored, because 8080 is already in use #912

PaulCombal opened this issue Apr 22, 2019 · 12 comments · Fixed by #989

Comments

@PaulCombal
Copy link

I just downloaded the AppImage from the Readme, and it won't connect to IPFS because, as described in the log, my port 8080 is already in use.

2019-04-22T14:52:31.218Z error: [ipfsd] %vCommand failed: /tmp/.mount_ipfs-d8VxVBQ/resources/app.asar.unpacked/node_modules/go-ipfs-dep/go-ipfs/ipfs daemon --migrate=true --routing=dhtclient --enable-gc=true
Error: serveHTTPGateway: manet.Listen(/ip4/127.0.0.1/tcp/8080) failed: listen tcp4 127.0.0.1:8080: bind: address already in use

This port is very common and is even used by Skype, so maybe you could use another port if 8080 is taken?

Thank you

@PaulCombal PaulCombal changed the title [Linux] IPFS has errored, because 8080 is already in use IPFS has errored, because 8080 is already in use Apr 22, 2019
@hacdias
Copy link
Member

hacdias commented Apr 27, 2019

Hello @PaulCombal! Thanks for reporting this. Perhaps we could ask the user which ports they'd like to use if those are not available. IPFS uses some different ports for different endpoints (such as 8080 for the gateway and 5001 for the API). Would you, as an user, prefer to be asked which ports to pick or let us pick a random port?

@lidel what do you think about this?

@PaulCombal
Copy link
Author

I guess your tool is designed to be used by non-developers, who have no idea what a port is. I think the best idea would be to try other ports until one is found, without prompting the user.

For power users, maybe leaving the option to override the port with an environment variable or a config file would be a great idea though.

For example Skype, again, would never ask you which port you want to listen to before starting, it just finds a way.

@lidel
Copy link
Member

lidel commented Apr 29, 2019

I agree with @PaulCombal:

  • Regular user should not be bothered, it should "just work" and pick the first free port in range (8080+ for gateway, 5001+ for api)
  • Power user can always edit JSON on Settings and restart the app to use different one

@olizilla thoughts? I assume on Mac you never seen any user friendly apps asking which port to use :)

@Stebalien
Copy link
Member

FYI, you can specify the 0 port and go-ipfs will pick a new one every time. However, we don't have a good way to ask go-ipfs which port it's using. Our tests scrape daemon status text for Gateway ... listening on ADDR.

@hacdias
Copy link
Member

hacdias commented Apr 30, 2019

But, should this only be done the first time it is run? Or every time if there is a port being used already? I think there are pros and cons of each approach. For beginners/non-developers, it'd be nice if they'd never need to care. For more advanced users, it'd be bad to be changing the ports without their consent. What do you all think?

@PaulCombal
Copy link
Author

For more advanced users, it'd be bad to be changing the ports without their consent. What do you all think?

Isn't this why we should let them override the port to use in a config file / environment variable?
I think the UI should show somewhere that the error 'Port XXXX already in use', with a link to documentation on how to override a port (eg: a github readme)

At least that's the way I imagine things

@hacdias
Copy link
Member

hacdias commented May 1, 2019

Hmm... the problem is: for us to use a random port, we have to change the config so IPFS knows it should start in a random port. Although, how would we distinguish the following two scenarios:

  1. The user stars IPFS Desktop for the first time. Ports already busy. We update the settings to random. Works. Happy user.
  2. An advanced user, for some reason, has a busy port. We override theirs, by changing the config. Works. Unhappy user.

How do we know that the user wants us to override the port or not? Perhaps we could add a checkbox (checked by default) on the settings page. Just because it always envolves changing the settings.

@PaulCombal
Copy link
Author

PaulCombal commented May 2, 2019

I imagined those scenarios:

The override settings is not set:

  • Use a random port (eg: try range 8080 - 8100)

The override setting is set to port X:

  • Use port X

In both cases if no port can be used or the X port is already taken, then an error message should show.
I do not see a case where a first launch would cause this logic to fail.

EDIT:

How do we know that the user wants us to override the port or not? Perhaps we could add a checkbox (checked by default) on the settings page. Just because it always envolves changing the settings.

Using a config file / environment variable. I do not believe having a GUI to choose the port is necessary, but if you do, the save button should save changes to the said config file.

@hacdias
Copy link
Member

hacdias commented Jul 14, 2019

The easiest way to go, in my opinion, is to set new installations configurations for port 0 so it is set randomly. What do you think @lidel @olizilla?

I can't figure out a way to use a random port only when the defaults aren't available. That would require us to revert the options on shut down and somehow know that the user has changed the configuration.

Perhaps the best is to bootstrap with a random port and then let the user do whatever they want. Most likely, only a few people will notice they're not running on the default port.

Although I feel it would kind of break the connection with IPFS Companion as it searches the default API ports to connect to a node.

@lidel
Copy link
Member

lidel commented Jul 15, 2019

It would be pretty bad if we default to random port by default (UX regression for users who did not have any issues before 😭).

I think it should be possible to do a quick check of port availability during the startup, just like we check for ~/.ipfs/api or leftover locks.

We would do the check only when remote API endpoint is not set (lack of ~/.ipfs/api). Read the port from config (and default to 8080 if config does not exist yet). Then we run a check if port is taken and/or find a free one as a fallback.

There are existing libs that help with this, for example with get-port:

const getPort = require('get-port')
const defaultPort = 8080
const availablePort = await getPort({ port: defaultPort })) 
// Will use 8080 if available, otherwise fall back to a random port

The question is, what happens next, when availablePort !== defaultPort 😱

I see two options:

  • Option A: just make it work, don't bother user

    update port to availablePort in the config, so node starts with available one

    • 💢 introduces surface for very confusing workflows when default port is set in other tools like IPFS Companion
  • Option B: be explicit what is happening, give user a choice

    display dialog to user informing defaultPort is taken but avalablePort is free and ask if it is okay to start node on avalablePort instead

    • 👼 user understands when and why port changes and is able to update third party software

Thoughts?

@PaulCombal
Copy link
Author

Option B seems Ok to me. I believe adding a "Don't ask me again" checkbox is very important in this case.

@hacdias
Copy link
Member

hacdias commented Jul 15, 2019

I think the option B with a 'Dont ask me again' as @PaulCombal suggested would be the better option. Although I didn't want to bother users about this.

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 a pull request may close this issue.

4 participants