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

Commit 68561c8

Browse files
author
Alan Shaw
authored
fix: stop IPNS republisher ASAP (#1976)
This PR refactors the stop logic to perform stop actions in parallel for various components (where it is safe to do so). This means that libp2p gets stopped at the same time as the republisher. When libp2p stops it closes all connections meaning that the republsher is able to complete a running republish sooner. Before, we had to wait for republish to complete before stop happens (since there's no way to cancel a DHT put right now). License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 08b6740 commit 68561c8

File tree

5 files changed

+78
-25
lines changed

5 files changed

+78
-25
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"execa": "^1.0.0",
6969
"form-data": "^2.3.3",
7070
"hat": "0.0.3",
71-
"interface-ipfs-core": "~0.99.0",
71+
"interface-ipfs-core": "~0.99.1",
7272
"ipfsd-ctl": "~0.42.0",
7373
"libp2p-websocket-star": "~0.10.2",
7474
"ncp": "^2.0.0",
@@ -130,7 +130,7 @@
130130
"libp2p": "~0.25.0-rc.5",
131131
"libp2p-bootstrap": "~0.9.3",
132132
"libp2p-crypto": "~0.16.0",
133-
"libp2p-kad-dht": "~0.14.11",
133+
"libp2p-kad-dht": "~0.14.12",
134134
"libp2p-keychain": "~0.4.1",
135135
"libp2p-mdns": "~0.12.0",
136136
"libp2p-mplex": "~0.8.4",

src/core/components/stop.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const series = require('async/series')
3+
const parallel = require('async/parallel')
44
const promisify = require('promisify-es6')
55

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

20-
const done = (err) => {
21-
if (err) {
22-
self.emit('error', err)
23-
return callback(err)
24-
}
25-
self.state.stopped()
26-
self.emit('stop')
27-
callback()
28-
}
29-
3020
self.state.stop()
3121
self._blockService.unsetExchange()
3222
self._bitswap.stop()
3323
self._preload.stop()
3424

35-
series([
36-
(cb) => self._ipns.republisher.stop(cb),
37-
(cb) => self._mfsPreload.stop(cb),
38-
(cb) => {
25+
parallel([
26+
cb => self._ipns.republisher.stop(cb),
27+
cb => self._mfsPreload.stop(cb),
28+
cb => {
3929
const libp2p = self.libp2p
4030
self.libp2p = null
4131
libp2p.stop(cb)
42-
},
43-
(cb) => self._repo.close(cb)
44-
], done)
32+
}
33+
], err => {
34+
self._repo.close(closeErr => {
35+
if (err || closeErr) {
36+
self.emit('error', err || closeErr)
37+
return callback(err || closeErr)
38+
}
39+
40+
self.state.stopped()
41+
self.emit('stop')
42+
callback()
43+
})
44+
})
4545
})
4646
}

test/core/interface.spec.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,18 @@ describe('interface-ipfs-core tests', function () {
7979
tests.key(CommonFactory.create({
8080
spawnOptions: {
8181
args: ['--pass ipfs-is-awesome-software'],
82-
initOptions: { bits: 512 }
82+
initOptions: { bits: 512 },
83+
config: {
84+
Bootstrap: [],
85+
Discovery: {
86+
MDNS: {
87+
Enabled: false
88+
},
89+
webRTCStar: {
90+
Enabled: false
91+
}
92+
}
93+
}
8394
}
8495
}))
8596

@@ -183,6 +194,18 @@ describe('interface-ipfs-core tests', function () {
183194
config = null
184195
}
185196

197+
config = config || {
198+
Bootstrap: [],
199+
Discovery: {
200+
MDNS: {
201+
Enabled: false
202+
},
203+
webRTCStar: {
204+
Enabled: false
205+
}
206+
}
207+
}
208+
186209
const spawnOptions = { repoPath, config, initOptions: { bits: 512 } }
187210

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

test/core/preload.spec.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ describe('preload disabled', function () {
340340
config: {
341341
Addresses: {
342342
Swarm: []
343-
}
343+
},
344+
Bootstrap: []
344345
},
345346
preload: {
346347
enabled: false,
@@ -353,9 +354,15 @@ describe('preload disabled', function () {
353354

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

356-
after((done) => ipfs.stop(done))
357+
after(function (done) {
358+
this.timeout(50 * 1000)
359+
ipfs.stop(done)
360+
})
357361

358-
after((done) => repo.teardown(done))
362+
after(function (done) {
363+
this.timeout(50 * 1000)
364+
repo.teardown(done)
365+
})
359366

360367
it('should not preload if disabled', (done) => {
361368
ipfs.add(Buffer.from(hat()), (err, res) => {

test/http-api/interface.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,18 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
5959
tests.key(CommonFactory.create({
6060
spawnOptions: {
6161
args: ['--pass ipfs-is-awesome-software'],
62-
initOptions: { bits: 512 }
62+
initOptions: { bits: 512 },
63+
config: {
64+
Bootstrap: [],
65+
Discovery: {
66+
MDNS: {
67+
Enabled: false
68+
},
69+
webRTCStar: {
70+
Enabled: false
71+
}
72+
}
73+
}
6374
}
6475
}))
6576

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

133+
config = config || {
134+
Bootstrap: [],
135+
Discovery: {
136+
MDNS: {
137+
Enabled: false
138+
},
139+
webRTCStar: {
140+
Enabled: false
141+
}
142+
}
143+
}
144+
122145
const spawnOptions = { repoPath, config, initOptions: { bits: 512 } }
123146

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

0 commit comments

Comments
 (0)