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 daemon --offline returns 400 for /api/v0/stats/bw #853

Open
olizilla opened this issue Oct 7, 2018 · 4 comments
Open

ipfs daemon --offline returns 400 for /api/v0/stats/bw #853

olizilla opened this issue Oct 7, 2018 · 4 comments
Labels
exp/intermediate Prior experience is likely helpful kind/bug A bug in existing code (including security flaws) P2 Medium: Good to have, but can wait until someone steps up

Comments

@olizilla
Copy link
Member

olizilla commented Oct 7, 2018

If your run

ipfs daemon --offline 

then the API responds to requests for /api/v0/stats/bw with a 400 status code and the body:

{"Message":"this command must be run in online mode. Try running 'ipfs daemon' first","Code":1,"Type":"error"}

as we're using the bandwidth stats to determine if the connection is working, the Web UI asserts that the connection to IPFS has failed.

@olizilla olizilla added exp/intermediate Prior experience is likely helpful P2 Medium: Good to have, but can wait until someone steps up kind/bug A bug in existing code (including security flaws) labels Oct 7, 2018
@olizilla
Copy link
Member Author

olizilla commented Oct 7, 2018

We need to handle the situation where the stats/bw response is a 400 for offline mode. The connection is fine in that case, and the status page should inform the user that the node is in offline mode, in place of the bandwidth graph and the distribution of peers graph. They'll never show anything while we're offline anyway.

The peers page will show 0 peers, so it'd be worth adding a message on that page that explains why.

The connection indicator should be updated to denote that we are connected to IPFS but in offline mode.

@rafaelramalho19
Copy link
Contributor

@olizilla is the current behavior satisfactory to close this issue or is something missing?

@lidel
Copy link
Member

lidel commented Oct 23, 2020

@rafaelramalho19 I was revisiting this while testing ipfs/ipfs-companion#936 and this is still a problem.

When I run daemon in offline mode (ipfs daemon --offline) Web UI online check fails, stats.bw returns HTTP 400 when daemon runs in --offline mode, which in turn triggers "api is down" error page:

no-offline-2020-10-23--18-52-46

So we need fix described in #853 (comment) and a smarter detection of the --offline mode. It can be done by:

let peers
try {
  peers = await ipfs.swarm.peers({ timeout: 2500 })
} catch (error) {
  if (error.message.includes('action must be run in online mode')) {
    // node is running in offline mode (ipfs daemon --offline)
    // https://github.com/ipfs-shipyard/ipfs-companion/issues/790
    return [] // ipfs daemon --offline
  }
  // actual error handling...
}
  • switch API check from stats.bw to swarm.peers
  • return empty peer list when in offline mode (instead of error)
  • make it not fail when there are no peers

@boomshroom
Copy link

Fetching the bandwidth usage seems like it would of course error when offline. So some other method to check if the daemon is running should be used. Unfortunately, none of the commands in the documentation seem like simple pulse checks. Maybe id or commands?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exp/intermediate Prior experience is likely helpful kind/bug A bug in existing code (including security flaws) P2 Medium: Good to have, but can wait until someone steps up
Projects
No open projects
Status: Needs Grooming
Development

No branches or pull requests

4 participants