hmalphettes/redisdown

Unable to delete database when using remote redis

gerbenupinion opened this issue · 5 comments

In this setup I run express-pouchdb in combination with redisdown. I'm able to create, edit and delete documents. Creating a databases works as well. I'm only not able to delete a database. This causes the server to crash.

This issue appears when I run Redis on a different server then the pouchdb server which uses redisdown. When I try to delete the dabatase it will try to connect to 127.0.0.1:6379 instead of the given host and port.

It has been tested on a Ubuntu server with node version v0.10.40, v0.12.7 & v4.2.1.

Setting for redisdown.

opts.db = require('redisdown');
opts.port = 6379;
opts.host = 'redis.dev';

Request send:

DELETE /test HTTP/1.1
Host: redis.dev:80
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://pouchdb.dev:80
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36
X-CouchDB-CSRF: true
Referer: http://pouchdb.dev:80/_utils/

Log:

[info] GET /test/_all_docs?limit=21 200 - 172.17.0.12
[info] GET /test/_all_docs?startkey=%22_design%2F%22&endkey=%22_design0%22&include_docs=true&limit=501 200 - 172.17.0.12
[info] GET /_all_dbs 200 - 172.17.0.12
[info] GET /_utils/js/zeroclipboard/ZeroClipboard.swf?noCache=1444901336410 200 - 172.17.0.12
[info] GET /_utils/img/couch-watermark.png 200 - 172.17.0.12

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
    at errnoException (net.js:905:11)
    at Object.afterConnect [as oncomplete] (net.js:896:19)

It doesn't seem to be a redisdown issue.

When destroying a database any open connection is first closed and then reopened within the redisdown destroy function. This means the redisdown destroy function requires the same options param (host and port) as given when setting up a connection for a get or put request.

Oh! I was about to start working on it! Usually this type of issue does not go away by itself.
Just to be clear: indeed the static method RedisDown.destroy does require the connection parameters.
But the RedisDown.prototype.destroy does not need them.

If you can confirm that redisdown is following the best practices regarding how pouchdb is calling the destroy methods of levelup that would be awesome.
If there is some improvement to be done let me know.

At this moment the static method is called when closing a database connection.

https://github.com/pouchdb/pouchdb/blob/b77788bb6d7964efb18a7d1be572eb27dc46af4a/lib/adapters/leveldb/index.js#L1465

leveldown.destroy(name, cb);

I asked @nolanlawson in ticket pouchdb/express-pouchdb#264 if he can contribute to your question about best practices regarding how pouchdb is calling the destroy methods.

Thanks @gerbenupinion so it seems we are expected to keep a list of the connection parameters per database name. If that is what the other leveldowns are doing: so be it!

Published in 0.1.9