Skip to content

fix: Return node only after go-ipfs daemon is ready #150

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"dependencies": {
"async": "^2.1.5",
"go-ipfs-dep": "0.4.7",
"ipfs-api": "^12.1.7",
"ipfs-api": "^14.0.0",
"multiaddr": "^2.2.2",
"once": "^1.4.0",
"rimraf": "^2.6.1",
Expand Down
13 changes: 8 additions & 5 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,22 @@ class Node {
const str = String(data).trim()
const match = str.match(/API server listening on (.*)/)
const gwmatch = str.match(/Gateway (.*) listening on (.*)/)
const readyMatch = str.match(/Daemon is ready/)

if (match) {
this._apiAddr = multiaddr(match[1])
this.api = ipfs(match[1])
this.api.apiHost = this.apiAddr.nodeAddress().address
this.api.apiPort = this.apiAddr.nodeAddress().port
}

if (gwmatch) {
this._gatewayAddr = multiaddr(gwmatch[2])
this.api.gatewayHost = this.gatewayAddr.nodeAddress().address
this.api.gatewayPort = this.gatewayAddr.nodeAddress().port
}
if (gwmatch) {
this._gatewayAddr = multiaddr(gwmatch[2])
this.api.gatewayHost = this.gatewayAddr.nodeAddress().address
this.api.gatewayPort = this.gatewayAddr.nodeAddress().port
}

if (readyMatch) {
callback(null, this.api)
}
Copy link
Member

Choose a reason for hiding this comment

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

str.match is non blocking, if you found that bug happening, it means that the output was captured before go-ipfs had written everything. I believe that this doesn't solve the issue (🕸🕷), only silences it by not calling the callback with an undefined parameter. Let's add a else to callback with a error signalling that the daemon was not found ready.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this part was getting called multiple times (twice in this case), first with "API listening..." and then with "Gateway (readonly) listening...\nDaemon is ready". Not sure why or if that's the intended behaviour, but adding an else and an error callback will just make it fail always (from user's perspective).

@dignifiedquire I believe you refactored the exec code last time, any ideas here?

Copy link
Member

Choose a reason for hiding this comment

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

You can use http://npmjs.org/once

}
Expand Down