-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graceful stop #205
Graceful stop #205
Changes from 22 commits
00958a7
ec58831
1db2ae4
6ecc02a
252e1d5
c3315ac
67a2041
8cd5abe
b1dc8ee
4f0c14d
3b32c03
2aec828
22c4ae9
74f6dc8
a5d0ec5
b3444f8
162ffb8
36fbb7a
5fc58bb
b1f5538
a61fa50
2d3cf40
3ffcee3
4ad247b
36aa183
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,6 @@ dist | |
docs | ||
|
||
.idea | ||
|
||
.nyc_output | ||
.vscode |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,10 +65,13 @@ class FactoryInProc { | |
callback = options | ||
options = {} | ||
} | ||
const IPFS = this.exec | ||
new IPFS(options).version((err, _version) => { | ||
if (err) { callback(err) } | ||
callback(null, _version) | ||
|
||
const node = new Node(options) | ||
node.once('ready', () => { | ||
node.init((err) => { | ||
if (err) { return callback(err) } | ||
node.version(callback) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is very odd to me that we start a new instance of IPFS to get the version. This will create a memory leak + it will lock the repo for a consequent node spawn. @dryajov can you expand why to do it this way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @diasdavid I'm not aware of any other way to get the version - is there a better one you can suggest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, the instance is not started, it is simply initialized with a repo, to start it we would have to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dryajov are you saying that a repo is created to just get the version of ipfs? Sound like the node.version should work offline/un'init for the info it can provide, namely, the impl version. If it was absolutely impossible (which it isn't), at least there should be a cleanup step here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I thought about just using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it turns out that the version is read by the repo here - https://github.com/ipfs/js-ipfs/blob/494da7f8c5b35f491f22a986ff5e8c456cc0e602/src/core/components/version.js#L14...L24. I think that's an overkill and we should separate the repo version from the ipfs version, that way we don't need a repo. If noone objects I can go ahead and make that change in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a need for a Repo version and IPFS version, that is correct. It should be ok to get the IPFS version without the Repo existing though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed - I'm making the change in IPFS to allow for that. |
||
}) | ||
} | ||
|
||
|
@@ -97,7 +100,6 @@ class FactoryInProc { | |
} | ||
|
||
const options = defaults({}, opts, defaultOptions) | ||
|
||
options.init = typeof options.init !== 'undefined' | ||
? options.init | ||
: true | ||
|
@@ -129,15 +131,16 @@ class FactoryInProc { | |
} | ||
|
||
const node = new Node(options) | ||
|
||
series([ | ||
(cb) => options.init | ||
? node.init(cb) | ||
: cb(), | ||
(cb) => options.start | ||
? node.start(options.args, cb) | ||
: cb() | ||
], (err) => callback(err, node)) | ||
node.once('ready', () => { | ||
series([ | ||
(cb) => options.init | ||
? node.init(cb) | ||
: cb(), | ||
(cb) => options.start | ||
? node.start(options.args, cb) | ||
: cb() | ||
], (err) => callback(err, node)) | ||
}) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,16 @@ const createRepo = require('./utils/repo/create-nodejs') | |
const defaults = require('lodash.defaults') | ||
const waterfall = require('async/waterfall') | ||
const debug = require('debug') | ||
const EventEmitter = require('events') | ||
|
||
const log = debug('ipfsd-ctl:in-proc') | ||
|
||
let IPFS = null | ||
|
||
/** | ||
* ipfsd for a js-ipfs instance (aka in-process IPFS node) | ||
*/ | ||
class Node { | ||
class Node extends EventEmitter { | ||
/** | ||
* Create a new node. | ||
* | ||
|
@@ -21,9 +24,10 @@ class Node { | |
* @returns {Node} | ||
*/ | ||
constructor (opts) { | ||
super() | ||
this.opts = opts || {} | ||
|
||
const IPFS = this.opts.exec | ||
IPFS = this.opts.exec | ||
|
||
this.opts.args = this.opts.args || [] | ||
this.path = this.opts.repoPath | ||
|
@@ -68,6 +72,8 @@ class Node { | |
EXPERIMENTAL: this.opts.EXPERIMENTAL, | ||
libp2p: this.opts.libp2p | ||
}) | ||
|
||
this.exec.once('ready', () => this.emit('ready')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use a different pattern than the one used for ipfs-daemon (new Node + node.start)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe not doing that can end up in race conditions - take a look at maybeOpenRepo, its called by the IPFS constructor through There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I'm weird'ed out is that in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, I see - we're not actually starting the node since IPFS is constructed with both, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Makes sense then. Thanks for clarifying :) |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this starting the node? I'm sure this is causing repo lock just to check the version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @dryajov, curious about this as there is a TODO to fix this on the go/js factory. Did the mentioned solution hit roadblocks originally? Can we make an issue and work on it separate from this PR?