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

express-pouchdb allocates infinite memory when given a defunct PouchDB #436

Open
ben0x539 opened this issue Jul 6, 2020 · 0 comments
Open

Comments

@ben0x539
Copy link

ben0x539 commented Jul 6, 2020

var http = require('http');
var PouchDB = require('pouchdb');

var app = require('express-pouchdb')(PouchDB.defaults({
  prefix: './non-existent-path/',
}))

app.listen(3000, function() {
  http.get('http://localhost:3000/db/hello'); // delayed explosion
});

(node:13549) UnhandledPromiseRejectionWarning: OpenError: IO error: ./non-existent-path/_replicator/LOCK: No such file or directory

Despite the warning, we continue on with a non-functional pouchdb object backing those routes. When trying to handle a request, this bit of code gets stuck forever while allocating more and more promises:

function getUsersDB() {
// calls itself until usersDBPromise is a available
if (!usersDBPromise) {
return new Promise(function (resolve) {
setImmediate(function () {
resolve(getUsersDB());
});
});
}
return usersDBPromise;
}

After busylooping while growing to a few gigabytes in size, node gets fed up and terminates.

This could probably be mitigated by only using one promise there and only repeating the setImmediate (or even setTimeout) call, but ultimately we should probably just be erroring out earlier and not let it come that far.

It's a very low impact crash that's easily avoided, but jumping into an unfamiliar codebase and not realizing the significance of the above warning, it took me a while to catch on. :)

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

No branches or pull requests

1 participant