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

stop() throws error: libp2p node is not started yet #1330

Closed
coyotespike opened this issue Apr 27, 2018 · 8 comments
Closed

stop() throws error: libp2p node is not started yet #1330

coyotespike opened this issue Apr 27, 2018 · 8 comments

Comments

@coyotespike
Copy link

coyotespike commented Apr 27, 2018

  • Version: version: '0.28.1', repo: 6, commit: ''
  • Platform: Ubuntu
  • Subsystem: libp2p

Type: Bug

Severity: Medium

Description: When running tests with Jest, one test produces this error before going on to complete successfully.

Steps to reproduce the error:

In each test suite, I have:

beforeAll(async () => {
  await ipfs.ready();
});

afterAll(async () => {
  await ipfs.stop();
});

ipfs.ready is simply a promise that returns when IPFS emits the ready event.

There's no difference in setup, but one test suite always produces the error libp2p node is not started yet. Running ipfs.stop() is necessary in order to free up the resource for the next testing suite. It's also necessary to use jest --runInBand to run the test suites sequentially.

I have tried using globalSetup to get around this but without success. Possibly related to #874 and #841. Full output below.

    Error: The libp2p node is not started yet
        at Object.unsubscribe (/<rootDir>/node_modules/libp2p/src/pubsub.js:38:15)
        at Object.unsubscribe (/<rootDir>/node_modules/ipfs/src/core/components/pubsub.js:29:31)
        at PubSubRoom.once (/<rootDir>/node_modules/ipfs-pubsub-room/src/index.js:121:25)
        at Object.onceWrapper (events.js:254:19)
        at PubSubRoom.emit (events.js:159:13)
        at PubSubRoom.leave (/<rootDir>/node_modules/ipfs-pubsub-room/src/index.js:60:10)
        at IPFS.emit (events.js:159:13)
        at done (/<rootDir>/node_modules/ipfs/src/core/components/stop.js:26:12)
        at /<rootDir>/node_modules/async/internal/parallel.js:39:9
        at /<rootDir>/node_modules/async/internal/once.js:12:16
        at replenish (/<rootDir>/node_modules/async/internal/eachOfLimit.js:59:25)
        at iterateeCallback (/<rootDir>/node_modules/async/internal/eachOfLimit.js:49:17)
        at /<rootDir>/node_modules/async/internal/onlyOnce.js:12:16
        at /<rootDir>/node_modules/async/internal/parallel.js:36:13
        at series (/<rootDir>/node_modules/ipfs-repo/src/index.js:195:17)
        at /<rootDir>/node_modules/async/internal/parallel.js:39:9
        at /<rootDir>/node_modules/async/internal/once.js:12:16
        at replenish (/<rootDir>/node_modules/async/internal/eachOfLimit.js:59:25)
        at iterateeCallback (/<rootDir>/node_modules/async/internal/eachOfLimit.js:49:17)
        at /<rootDir>/node_modules/async/internal/onlyOnce.js:12:16
        at /<rootDir>/node_modules/async/internal/parallel.js:36:13
        at series (/<rootDir>/node_modules/ipfs-repo/src/index.js:193:9)
        at /<rootDir>/node_modules/async/internal/parallel.js:31:39
        at replenish (/<rootDir>/node_modules/async/internal/eachOfLimit.js:64:17)
        at iterateeCallback (/<rootDir>/node_modules/async/internal/eachOfLimit.js:49:17)
        at /<rootDir>/node_modules/async/internal/onlyOnce.js:12:16
        at /<rootDir>/node_modules/async/internal/parallel.js:36:13
        at /<rootDir>/node_modules/async/internal/parallel.js:39:9
        at /<rootDir>/node_modules/async/internal/once.js:12:16
        at replenish (/<rootDir>/node_modules/async/internal/eachOfLimit.js:59:25)
        at iterateeCallback (/<rootDir>/node_modules/async/internal/eachOfLimit.js:49:17)
        at /<rootDir>/node_modules/async/internal/onlyOnce.js:12:16
        at /<rootDir>/node_modules/async/internal/parallel.js:36:13
        at /<rootDir>/node_modules/graceful-fs/graceful-fs.js:43:10
        at /<rootDir>/node_modules/graceful-fs/graceful-fs.js:43:10
        at /<rootDir>/node_modules/graceful-fs/graceful-fs.js:43:10
        at FSReqWrap.oncomplete (fs.js:149:20)
@coyotespike coyotespike changed the title Bug in test: libp2p node is not started yet stop() throws error: libp2p node is not started yet Apr 27, 2018
@daviddias
Copy link
Member

@coyotespike could you please share the snipped where you create the IPFS node?

@coyotespike
Copy link
Author

@diasdavid Sure thing!

import IPFS from 'ipfs';

export default function getIPFS(options) {
  const ipfs = new IPFS(options);
  let readyResolve = null;
  let readyReject = null;
  const isReady = new Promise((resolve, reject) => {
    readyResolve = resolve;
    readyReject = reject;
  });

  ipfs.on('ready', () => {
    console.log('IPFS is ready...');
    readyResolve(true);
  });

  ipfs.on('error', e => {
    console.error('IPFS failed to start: ', e);
    readyReject(e);
  });

  ipfs.ready = () => isReady;
  return ipfs;
}

const ipfs = getIPFS(ipfsOptions);

@daviddias
Copy link
Member

What does the ipfsOptions look like?

@coyotespike
Copy link
Author

coyotespike commented Apr 30, 2018

It is nothing fancy:

const ipfsOptions = {
  libp2p: {
    modules: {
      connection: {
        transport: [new TCP()],
        muxer: [SPDY],
        crypto: [SECIO],
      },
    },
  },
  config: {
    Addresses: {
      Swarm: [
        '/ip4/127.0.0.1/tcp/4001',
        '/ip4/127.0.0.1/tcp/4002/ws',
        '/ip4/0.0.0.0/tcp/4002',
        '/ip4/127.0.0.1/tcp/9999/ws',
      ],
      Announce: [],
      NoAnnounce: [],
      API: '/ip4/127.0.0.1/tcp/5001',
      Gateway: '/ip4/127.0.0.1/tcp/8080',
    },
  },
  EXPERIMENTAL: {
    pubsub: true,
    relay: {
      enabled: true,
      hop: {
        enabled: true,
      },
    },
  },
};

A lot of that is probably unnecessary.

@chmanie
Copy link

chmanie commented May 1, 2018

Currently there are problems with using globalSetup in jest when running tests in parallel which might lead to unexpected behaviour: jestjs/jest#5731

Try running the tests serially.

@coyotespike
Copy link
Author

Currently, to prevent race conditions within unit tests, or between unit tests and integration tests, I'm using --runInBand, and not using globalSetup.

@alanshaw
Copy link
Member

Hey @coyotespike looking at the stack trace, it seems like https://github.com/ipfs-shipyard/ipfs-pubsub-room is unsubscribing an internal pubsub handler after the js-ipfs node has stopped.

It registers a listener for the IPFS node stopping here:

https://github.com/ipfs-shipyard/ipfs-pubsub-room/blob/c13b4612af5d29448c68ca701db8a9282babec9d/src/index.js#L43

...which, when triggered, calls leave and emits "stop" on itself:

https://github.com/ipfs-shipyard/ipfs-pubsub-room/blob/c13b4612af5d29448c68ca701db8a9282babec9d/src/index.js#L54-L61

...which attempts to unsubscribe this handler on the stopped IPFS node:

https://github.com/ipfs-shipyard/ipfs-pubsub-room/blob/c13b4612af5d29448c68ca701db8a9282babec9d/src/index.js#L120-L122

This looks like a separate issue to the issues you referenced and you should open an issue on the ipfs-pubsub-room repo to report it.

Heads up @pgte

@coyotespike
Copy link
Author

Thanks for the detective work @alanshaw! that makes sense, I'll file an issue with ipfs-pubsub-room.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants