Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CouchDB replication is not working properly behind a proxy

Note: Made some updates based on new information. Old ideas have been added as comments below. Note: Made some updates (again) based on new information. Old ideas have been added as comments below (again).

We are running two instances of CouchDB on separate computers behind Apache reverse proxies. When attempting to replicate between the two instances:

curl -X POST http://user:pass@localhost/couchdb/_replicate -d '{ "source": "db1", "target": "http://user:[email protected]/couchdb/db1" }' --header "Content-Type: application/json"

(we started using curl to debug the problem)

we receive an error similar to:

{"error":"case_clause","reason":"{error,\n    {{bad_return_value,\n         {invalid_json,\n             <<\"<!DOCTYPE HTML PUBLIC \\\"-//IETF//DTD HTML 2.0//EN\\\">\\n<html><head>\\n<title>404 Not Found</title>\\n</head><body>\\n<h1>Not Found</h1>\\n<p>The requested URL /couchdb/db1/_local/01e935dcd2193b87af34c9b449ae2e20 was not found on this server.</p>\\n<hr>\\n<address>Apache/2.2.3 (Red Hat) Server at 10.1.100.59 Port 80</address>\\n</body></html>\\n\">>}},\n     {child,undefined,\"01e935dcd2193b87af34c9b449ae2e20\",\n         {gen_server,start_link,\n             [couch_rep,\n              [\"01e935dcd2193b87af34c9b449ae2e20\",\n               {[{<<\"source\">>,<<\"db1\">>},\n                 {<<\"target\">>,\n                  <<\"http://user:[email protected]/couchdb/db1\">>}]},\n               {user_ctx,<<\"user\">>,\n                   [<<\"_admin\">>],\n                   <<\"{couch_httpd_auth, default_authentication_handler}\">>}],\n              []]},\n         temporary,1,worker,\n         [couch_rep]}}}"}

So after further research it appears that apache returns this error without attempting to access CouchDB (according to the log files). To be clear when fed the following URL

/couchdb/db1/_local/01e935dcd2193b87af34c9b449ae2e20

Apache passes the request to CouchDB and returns CouchDB's 404 error. On the other hand when replication occurs the URL actually being passed is

/couchdb/db1/_local%2F01e935dcd2193b87af34c9b449ae2e20

which apache determines is a missing document and returns its own 404 error for without ever passing the request to CouchDB. This at least gives me some new leads but I could still use help if anyone has an answer offhand.

like image 351
Wesley Avatar asked Mar 08 '11 20:03

Wesley


1 Answers

The source CouchDB (localhost) is telling you that the remote URL was invalid. Instead of a CouchDB response, the source is receiving the Apache httpd proxy's file-not-found response.

Unfortunately, you may have some reverse-proxy troubleshooting to do. My first guess is the Host header the source is sending to the target. Perhaps it's different from when you connect directly from a third location?

Finally, I think you probably know this, but the path

/couchdb/db1/_local%2F01e935dcd2193b87af34c9b449ae2e20

Is not a standard CouchDB path. By the time CouchDB sees a request, it should have the /couchdb stripped, so the query is for a document called _local%2f... in the database called db1.

Incidentally, it is very important not to let the proxy modify the paths before they hit couch. In particular, if you send %2f then CouchDB had better receive %2f and if you send / then CouchDB had better receive /.

like image 159
JasonSmith Avatar answered Oct 14 '22 03:10

JasonSmith