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

Commit ca4da73

Browse files
committed
WIP on preventing crash with starting node twice
1 parent 706ada2 commit ca4da73

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/core/boot.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,21 @@ module.exports = (self) => {
4949

5050
if (doInit) {
5151
self.log('boot:doInit')
52-
tasks.push((cb) => self.init(initOptions, cb))
52+
tasks.push((cb) => {
53+
console.log('Doing init')
54+
self._repo.exists((err, exists) => {
55+
if (err) cb(err)
56+
console.log('exists', err, exists)
57+
if (exists) {
58+
cb(null, true)
59+
} else {
60+
self.init(initOptions, (err, res) => {
61+
console.log('init', err, res)
62+
cb(err, res)
63+
})
64+
}
65+
})
66+
})
5367
next(null, true)
5468
} else if (!repoOpen) {
5569
self._repo.exists(next)

test/core/create-node.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,19 @@ describe('create node', () => {
203203
(cb) => node.stop(cb)
204204
], done)
205205
})
206+
207+
it('can start node twice without crash', (done) => {
208+
const repo = createTempRepo()
209+
let node = new IPFS({repo, config: {Bootstrap: []}})
210+
series([
211+
(cb) => node.once('start', cb),
212+
(cb) => node.stop(cb),
213+
(cb) => {
214+
node = new IPFS({repo, config: {Bootstrap: []}})
215+
node.on('error', cb)
216+
node.once('start', cb)
217+
},
218+
(cb) => node.stop(cb)
219+
], done)
220+
})
206221
})

0 commit comments

Comments
 (0)