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

Commit 4f763ef

Browse files
committed
fix: only try to initialize if not init already
1 parent 706ada2 commit 4f763ef

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/core/boot.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,25 @@ module.exports = (self) => {
4747

4848
const tasks = []
4949

50-
if (doInit) {
51-
self.log('boot:doInit')
52-
tasks.push((cb) => self.init(initOptions, cb))
53-
next(null, true)
54-
} else if (!repoOpen) {
55-
self._repo.exists(next)
56-
}
50+
self._repo.exists((err, repoExists) => {
51+
if (err) {
52+
return done(err)
53+
}
54+
if (doInit && !repoExists) {
55+
tasks.push((cb) => self.init(initOptions, cb))
56+
}
57+
if (repoExists) {
58+
tasks.push(maybeOpenRepo)
59+
}
60+
next(null, repoExists)
61+
})
5762

5863
function next (err, hasRepo) {
5964
self.log('boot:next')
6065
if (err) {
6166
return done(err)
6267
}
6368

64-
if (hasRepo && !doInit) {
65-
self.log('boot:maybeopenreop')
66-
tasks.push(maybeOpenRepo)
67-
}
68-
6969
if (setConfig) {
7070
self.log('boot:setConfig')
7171
if (!hasRepo) {

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)