Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

ipfs.stop leaves process hanging #1168

Closed
alanshaw opened this issue Jan 2, 2018 · 19 comments
Closed

ipfs.stop leaves process hanging #1168

alanshaw opened this issue Jan 2, 2018 · 19 comments
Assignees
Labels
exp/expert Having worked on the specific codebase is important help wanted Seeking public contribution on this issue kind/bug A bug in existing code (including security flaws) P1 High: Likely tackled by core team if no one steps up

Comments

@alanshaw
Copy link
Member

alanshaw commented Jan 2, 2018

  • Version: 0.27.5
  • Platform: Node.js
  • Subsystem: n/a

Type:

Bug

Severity:

High

Description:

ipfs.stop(cb) calls cb but does not completely stop the node.

wtfnode says that the following interval is still active:

- Intervals:
  - (3600000 ~ 60 min) (anonymous) @ /Users/alan/Code/protocol-labs/ipfs-postmsg-proxy/node_modules/libp2p-kad-dht/src/providers.js:203

Note libp2p-kad-dht/src/providers.js:203 sets up a function to "cleanup" every hour, but this cannot be canceled.

Steps to reproduce the error:

Create a new js-ipfs instance and call stop, your Node.js process will not exit.

@dryajov dryajov self-assigned this Jan 2, 2018
@victorb
Copy link
Member

victorb commented Jan 3, 2018

I think I've seen this a couple of times in the test, as aegir refuses to completely exit after finishing running all the tests.

alanshaw added a commit to ipfs-inactive/ipfs-postmsg-proxy that referenced this issue Jan 3, 2018
@victorb
Copy link
Member

victorb commented Jan 4, 2018

Code for reproducing (should be testing with lots of different configs though, as the kad-dht issue doesn't show up with default config):

const wtfnode = require('wtfnode')
const ipfs = require('./src/core')

const node = new ipfs()

node.on('ready', () => {
  console.log('node ready, stopping in five seconds')
  setTimeout(node.stop, 5000)
})

node.on('stop', () => {
  console.log('node stopped')
  setTimeout(wtfnode.dump, 1000)
})

@daviddias
Copy link
Member

@victorbjelkholm try using .once, otherwise, those event listeners will never cleared

@victorb
Copy link
Member

victorb commented Jan 9, 2018

@diasdavid hm, seemed to work fine after fixing libp2p/js-libp2p-mdns#63, the event listener doesn't show up and the process exists successfully.

➜  js-ipfs git:(master) ✗ node forever2.js
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/ipfs/QmcVAXh8piydnLxZB67fTuhQuaWCWvJf9HPTix2wnirv8V
Swarm listening on /ip4/127.0.0.1/tcp/4002/ipfs/QmcVAXh8piydnLxZB67fTuhQuaWCWvJf9HPTix2wnirv8V
Swarm listening on /ip4/10.0.13.14/tcp/4002/ipfs/QmcVAXh8piydnLxZB67fTuhQuaWCWvJf9HPTix2wnirv8V
node ready, stopping in five seconds
node stopped
[WTF Node?] open handles:
- File descriptors: (note: stdio always exists)
  - fd 1 (tty) (stdio)
  - fd 2 (tty) (stdio)
- Timers:
  - (2000 ~ 2 s) (anonymous) @ /home/user/projects/ipfs/js-ipfs/node_modules/libp2p-tcp/src/listener.js:64

@alanshaw
Copy link
Member Author

alanshaw commented Jan 9, 2018

Is there something I can test out to help?

@alanshaw
Copy link
Member Author

alanshaw commented Jan 11, 2018

Script to reproduce:

const wtf = require('wtfnode')
const IPFS = require('ipfs')

console.log('IPFS node starting')

const node = new IPFS({
  EXPERIMENTAL: {
    dht: true
  }
})

node.once('ready', () => {
  console.log('IPFS node ready')
  node.stop(() => {
    console.log('IPFS node stopped')
    setTimeout(() => wtf.dump(), 5000)
  })
})

/*
OUTPUT:

IPFS node starting
Swarm listening on /ip4/127.0.0.1/tcp/49645/ipfs/QmU8eJXWVYudzSrV5fxQuptmK1haqMG6E1eKP47xuF4e1K
IPFS node ready
IPFS node stopped
[WTF Node?] open handles:
- File descriptors: (note: stdio always exists)
  - fd 1 (tty) (stdio)
  - fd 2 (tty) (stdio)
- Intervals:
  - (3600000 ~ 60 min) (anonymous) @ /Users/alan/Desktop/test/node_modules/libp2p-kad-dht/src/providers.js:203
  */

@daviddias daviddias added status/ready Ready to be worked exp/expert Having worked on the specific codebase is important help wanted Seeking public contribution on this issue P1 High: Likely tackled by core team if no one steps up kind/bug A bug in existing code (including security flaws) labels Jan 25, 2018
@sagivo
Copy link

sagivo commented Jan 29, 2018

having the same issue here.

@dryajov
Copy link
Member

dryajov commented Jan 29, 2018

@alanshaw I believe you have to call process.exit() yourself as stop only stops the in-process daemon, but doesn't exit the process itself - https://github.com/ipfs/js-ipfs/blob/master/src/core/components/stop.js

@richardschneider
Copy link
Contributor

@dryajov Should not have to call process.exit(), as node will exit when there is nothing on the event loop,

@sagivo
Copy link

sagivo commented Jan 29, 2018

yeah, calling exit is not a good solution.

@dryajov
Copy link
Member

dryajov commented Jan 29, 2018

good point @richardschneider @sagivo

@richardschneider richardschneider self-assigned this Jan 30, 2018
@richardschneider
Copy link
Contributor

@diasdavid Need to release js-libp2p-mdns to NPM and then update deps in js-ipfs.

@richardschneider
Copy link
Contributor

Did a search of all libp2p repos for setInterval and it looks like they all clearInterval!

@daviddias
Copy link
Member

@richardschneider released libp2p-mdns as patch release. You should get it on your next fresh npm install

@alanshaw
Copy link
Member Author

Fixes the issue for me also, thanks @richardschneider

@ghost ghost removed the status/ready Ready to be worked label Jan 30, 2018
@sagivo
Copy link

sagivo commented Jan 30, 2018

yep, looking good

@mitra42
Copy link

mitra42 commented Jan 6, 2019

I'm seeing ipfs.stop() never calling its callback. I notice the examples above use event listeners, but the API defines it as having a callback . Should that be a new issue, or does it look like this one needs reopening ?

@alanshaw
Copy link
Member Author

alanshaw commented Jan 6, 2019

New issue please @mitra42 😄 - please could you provide reproducable example code? Its the stop even emitted but not the callback called?

@mitra42
Copy link

mitra42 commented Jan 6, 2019

Ok detailed new issue at #1806
I don't know if the stop event is emitted - I'm not using event listeners,

MicrowaveDev pushed a commit to galtproject/js-ipfs that referenced this issue May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
exp/expert Having worked on the specific codebase is important help wanted Seeking public contribution on this issue kind/bug A bug in existing code (including security flaws) P1 High: Likely tackled by core team if no one steps up
Projects
None yet
Development

No branches or pull requests

7 participants