Skip to content
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

fix: dont spawn node for local ops #110

Merged

Conversation

fsdiogo
Copy link
Contributor

@fsdiogo fsdiogo commented May 29, 2019

Fixes #95.

@fsdiogo
Copy link
Contributor Author

fsdiogo commented May 29, 2019

@achingbrain @olizilla can you guys take a look at this one?

My approach was to create a middleware that only runs in GET requests and starts a daemon, leaving other operations as is.

I wasn't sure about the update command, but it should be ok leaving it untouched, or am I wrong?

module.exports = async (options) => {
if (process.argv.slice(2)[0] === 'update-registry-index') {
return update(options)
}
return proxy(options)
}

@fsdiogo fsdiogo marked this pull request as ready for review May 29, 2019 16:16
@olizilla olizilla requested a review from achingbrain June 3, 2019 14:33
return next()
}

const ipfs = await startIpfs(options)
Copy link
Member

Choose a reason for hiding this comment

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

This does not return immediately so multiple parallel GET requests to the server cause multiple IPFS nodes to be created. Better to have res.locals.ipfs be a promise to resolve an IPFS node as multiple contexts can await on it and it'll only resolve once.

On that res.locals.ipfs would be better as req.app.ipfs so the single IPFS node is explicitly global to the app rather than storing it on res.locals which imply per-request scoping.

Copy link
Member

@achingbrain achingbrain Jun 4, 2019

Choose a reason for hiding this comment

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

By which I mean, when I run this locally I see this sort of thing as requests from npm come in.

The rejected promises are caused by all the IPFS instances fighting over the locked ipfs-repo.

😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
😈 Spawning an in-process IPFS node using repo at /Users/alex/.jsipfs
(node:5539) UnhandledPromiseRejectionWarning: Error: Lock file is already being held
    at options.fs.stat (/Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/proper-lockfile/lib/lockfile.js:68:47)
    at /Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:154:5)
(node:5539) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5539) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:5539) UnhandledPromiseRejectionWarning: Error: Lock file is already being held
    at options.fs.stat (/Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/proper-lockfile/lib/lockfile.js:68:47)
    at /Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:154:5)
(node:5539) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:5539) UnhandledPromiseRejectionWarning: Error: Lock file is already being held
    at options.fs.stat (/Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/proper-lockfile/lib/lockfile.js:68:47)
    at /Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:154:5)
(node:5539) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:5539) UnhandledPromiseRejectionWarning: Error: Lock file is already being held
    at options.fs.stat (/Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/proper-lockfile/lib/lockfile.js:68:47)
    at /Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:154:5)
(node:5539) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:5539) UnhandledPromiseRejectionWarning: Error: Lock file is already being held
    at options.fs.stat (/Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/proper-lockfile/lib/lockfile.js:68:47)
    at /Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:154:5)
(node:5539) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
(node:5539) UnhandledPromiseRejectionWarning: Error: Lock file is already being held
    at options.fs.stat (/Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/proper-lockfile/lib/lockfile.js:68:47)
    at /Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:154:5)
(node:5539) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 6)
(node:5539) UnhandledPromiseRejectionWarning: Error: Lock file is already being held
    at options.fs.stat (/Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/proper-lockfile/lib/lockfile.js:68:47)
    at /Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:154:5)
(node:5539) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 7)
(node:5539) UnhandledPromiseRejectionWarning: Error: Lock file is already being held
    at options.fs.stat (/Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/proper-lockfile/lib/lockfile.js:68:47)
    at /Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:154:5)
(node:5539) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 8)
(node:5539) UnhandledPromiseRejectionWarning: Error: Lock file is already being held
    at options.fs.stat (/Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/proper-lockfile/lib/lockfile.js:68:47)
    at /Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:154:5)
(node:5539) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 9)
(node:5539) UnhandledPromiseRejectionWarning: Error: Lock file is already being held
    at options.fs.stat (/Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/proper-lockfile/lib/lockfile.js:68:47)
    at /Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:154:5)
(node:5539) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 10)
(node:5539) UnhandledPromiseRejectionWarning: Error: Lock file is already being held
    at options.fs.stat (/Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/proper-lockfile/lib/lockfile.js:68:47)
    at /Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:154:5)
(node:5539) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 11)
(node:5539) UnhandledPromiseRejectionWarning: Error: Lock file is already being held
    at options.fs.stat (/Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/proper-lockfile/lib/lockfile.js:68:47)
    at /Users/alex/Documents/Workspaces/ipfs-shipyard/npm-on-ipfs/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqWrap.oncomplete (fs.js:154:5)

Copy link
Member

Choose a reason for hiding this comment

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

Anyway, I fixed it in #111 but can't push to the incoming branch this PR is based on so have all the changes there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that's weird, I don't think that happened to me 🤔

You're right, that is a better approach 👍

@achingbrain achingbrain merged commit 36f4e8f into ipfs-shipyard:master Jun 4, 2019
achingbrain added a commit that referenced this pull request Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dont spawn node for local operations like npm ls
2 participants