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

fix: double pre start #1437

Merged
merged 8 commits into from
Jul 15, 2018
Merged

fix: double pre start #1437

merged 8 commits into from
Jul 15, 2018

Conversation

alanshaw
Copy link
Member

@alanshaw alanshaw commented Jul 12, 2018

This is a fix for preStart being called twice but also a partial refactor of the boot sequence.

The problem is that preStart always needs to be called between init and start and was actually being called in boot.js (via the IPFS constructor if repo exists or is newly initialized) as well as in start.js.

The following permutations of constructing, initializing and starting show how preStart was being called twice:

const ipfs = new IPFS({ init: false, start: false })
ipfs.on('ready', () => {
  await ipfs.init()
  await ipfs.start()
})

preStart is called ✅
preStart is called once from ipfs.start()

const ipfs = new IPFS({ init: true, start: false })
ipfs.on('ready', () => {
  await ipfs.start()
})

preStart is called ✅
preStart is called once from boot.js (via the constructor) and again in ipfs.start()

const ipfs = new IPFS({ init: true, start: true })
ipfs.on('ready', () => {})

preStart is called ✅
preStart is called once from boot.js (via the constructor) and again via boot.js since it calls ipfs.start()


So having preStart called in boot.js and ipfs.start ensures it is always called, but in most cases it ends up being called twice.

This PR moves the call to preStart into init and ensures init is always called even if the repo already exists.

towards #1061
fixes #1162

License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
@ghost ghost assigned alanshaw Jul 12, 2018
@ghost ghost added the status/in-progress In progress label Jul 12, 2018
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT
Signed-off-by: Alan Shaw <alan@tableflip.io>
@alanshaw alanshaw changed the title [WIP] fix: double pre start fix: double pre start Jul 13, 2018
@alanshaw alanshaw requested a review from daviddias July 13, 2018 16:22
Copy link
Member

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM. I saw your question #1438 but if I'm seeing things correctly, it should not block this PR from being merged.

@alanshaw
Copy link
Member Author

Correct :D

@daviddias daviddias merged commit e6ad63e into master Jul 15, 2018
@daviddias daviddias deleted the fix/double-pre-start branch July 15, 2018 12:36
@ghost ghost removed the status/in-progress In progress label Jul 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple calls to pre-start
2 participants