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

fix: stop IPNS republisher ASAP #1976

Merged
merged 8 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"execa": "^1.0.0",
"form-data": "^2.3.3",
"hat": "0.0.3",
"interface-ipfs-core": "~0.99.0",
"interface-ipfs-core": "~0.99.1",
"ipfsd-ctl": "~0.42.0",
"libp2p-websocket-star": "~0.10.2",
"ncp": "^2.0.0",
Expand Down Expand Up @@ -130,7 +130,7 @@
"libp2p": "~0.25.0-rc.5",
"libp2p-bootstrap": "~0.9.3",
"libp2p-crypto": "~0.16.0",
"libp2p-kad-dht": "~0.14.11",
"libp2p-kad-dht": "~0.14.12",
"libp2p-keychain": "~0.4.1",
"libp2p-mdns": "~0.12.0",
"libp2p-mplex": "~0.8.4",
Expand Down
36 changes: 18 additions & 18 deletions src/core/components/stop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const series = require('async/series')
const parallel = require('async/parallel')
const promisify = require('promisify-es6')

module.exports = (self) => {
Expand All @@ -17,30 +17,30 @@ module.exports = (self) => {
return callback(new Error('Not able to stop from state: ' + self.state.state()))
}

const done = (err) => {
if (err) {
self.emit('error', err)
return callback(err)
}
self.state.stopped()
self.emit('stop')
callback()
}

self.state.stop()
self._blockService.unsetExchange()
self._bitswap.stop()
self._preload.stop()

series([
(cb) => self._ipns.republisher.stop(cb),
(cb) => self._mfsPreload.stop(cb),
(cb) => {
parallel([
cb => self._ipns.republisher.stop(cb),
cb => self._mfsPreload.stop(cb),
cb => {
const libp2p = self.libp2p
self.libp2p = null
libp2p.stop(cb)
},
(cb) => self._repo.close(cb)
], done)
}
], err => {
self._repo.close(closeErr => {
if (err || closeErr) {
self.emit('error', err || closeErr)
return callback(err || closeErr)
}

self.state.stopped()
self.emit('stop')
callback()
})
})
})
}
25 changes: 24 additions & 1 deletion test/core/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,18 @@ describe('interface-ipfs-core tests', function () {
tests.key(CommonFactory.create({
spawnOptions: {
args: ['--pass ipfs-is-awesome-software'],
initOptions: { bits: 512 }
initOptions: { bits: 512 },
config: {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled: false
},
webRTCStar: {
Enabled: false
}
}
}
}
}))

Expand Down Expand Up @@ -183,6 +194,18 @@ describe('interface-ipfs-core tests', function () {
config = null
}

config = config || {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled: false
},
webRTCStar: {
Enabled: false
}
}
}

const spawnOptions = { repoPath, config, initOptions: { bits: 512 } }

ipfsFactory.spawn(spawnOptions, (err, _ipfsd) => {
Expand Down
13 changes: 10 additions & 3 deletions test/core/preload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ describe('preload disabled', function () {
config: {
Addresses: {
Swarm: []
}
},
Bootstrap: []
},
preload: {
enabled: false,
Expand All @@ -353,9 +354,15 @@ describe('preload disabled', function () {

afterEach((done) => MockPreloadNode.clearPreloadCids(done))

after((done) => ipfs.stop(done))
after(function (done) {
this.timeout(50 * 1000)
ipfs.stop(done)
})

after((done) => repo.teardown(done))
after(function (done) {
this.timeout(50 * 1000)
repo.teardown(done)
})

it('should not preload if disabled', (done) => {
ipfs.add(Buffer.from(hat()), (err, res) => {
Expand Down
25 changes: 24 additions & 1 deletion test/http-api/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,18 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
tests.key(CommonFactory.create({
spawnOptions: {
args: ['--pass ipfs-is-awesome-software'],
initOptions: { bits: 512 }
initOptions: { bits: 512 },
config: {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled: false
},
webRTCStar: {
Enabled: false
}
}
}
}
}))

Expand Down Expand Up @@ -119,6 +130,18 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
config = undefined
}

config = config || {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled: false
},
webRTCStar: {
Enabled: false
}
}
}

const spawnOptions = { repoPath, config, initOptions: { bits: 512 } }

ipfsFactory.spawn(spawnOptions, (err, _ipfsd) => {
Expand Down