Repository: apache/couchdb

Issue #1810: Requests return 400 Bad Request when URL length exceeds 1460 characters
Created: 2018-12-13T16:07:40Z
When using chttpd.server_option = [{recbuf, undefined}], requests with URL length exceeding 1459 characters fail with 400 Bad Request with no error in the logs. (The relevant URL length excludes protocol and userinfo).
Example of failing request:
curl -v http://127.0.0.1:5984/_users/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

URL length is 1467 (1460 excluding protocol and userinfo)
Expected Behavior
Should return:
Host: 127.0.0.1:5984
User-Agent: curl/7.58.0
Accept: */*
 
HTTP/1.1 404 Object Not Found
Cache-Control: must-revalidate
Content-Length: 41
Content-Type: application/json
Date: Thu, 13 Dec 2018 13:18:50 GMT
Server: CouchDB/2.3.0 (Erlang OTP/20)
X-Couch-Request-ID: 0b4ad7148f
X-CouchDB-Body-Time: 0 
{"error":"not_found","reason":"missing"}

Current Behavior
Actually returns:
HTTP/1.1
Host: 127.0.0.1:5984
User-Agent: curl/7.58.0
Accept: */*
 
HTTP/1.1 400 Bad Request
Connection: close
Content-Length: 0
Date: Thu, 13 Dec 2018 13:15:09 GMT
Server: MochiWeb/1.0 (Any of you quaids got a smint?) 

Example of successful request:
curl -v http://127.0.0.1:5984/_users/aaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

URL length is 1466 (1459 excluding protocol and userinfo).
Possible Cause
It appears that, by not setting a recbuf value, mochiweb_socket_server sockets end up with a buffer size of 1460 (the user-level buffer - http://erlang.org/doc/man/inet.html), which causes this limitation (recbuf and sndbuf are indeed defaulting to much larger values).
This default value of 1460 seems to be coming from Erl inet_drv.c and initialized here.
Steps to Reproduce
Install CouchDB 2.3 (or build from master) and run with default configuration (specifically chttpd.server_option = [{recbuf, undefined}]).
Execute a request with a URL length (excluding protocol and authority) exceeding 1460 characters (method or endpoint appear to be irrelevant).
Context
We are using PouchDB to interact with our CouchDB database and ran into this error with view queries. PouchDB does issue a POST request instead of a GET, but only when the query string exceeds 2000 characters (see here).
Your Environment

Version used: 2.3.0, master
Using: Chrome, cURL, wget
Operating system: Ubuntu 18, Ubuntu 16 (desktop)

Even if it is decided that this is desired behavior, I believe this change should at least be documented.

Duplicate issue #1979: Database replication stops working after 10 minutes (replicator crash)
Created: 2019-03-15T10:29:21Z
I am currently working on a proof of concept prototype application that basicaly performs the below in order to prove how stable CouchDB replication is.
But unfortunately by looping the test below in around 10 minutes replication suddenly stops wokring from counta->countb and seems like the only
thing that is working afterwards is deleting replication document and both databases and start all over creating databases etc.
Description
I have been able to reproduce this several time (test application written in C# and using my own small CouchDB implementation using RestSharp).
I have attached log file that shows that the replication process crashes - so is this a bug and what to do from here??
Steps to Reproduce
Precondiction:
One 'counta' database with one document: {
"_id": "countId",
"Value": 0
}
One 'countb' database with one document: {
"_id": "countId",
"Value": 0
}
Test application (Merge the highest number wins):

Remove A->B replication if exist (database counta->countb)
Remove B->A replication if exist (database countb->counta)
Create A->B replication (database counta->countb)
Wait 5 seconds
Set count A = 0
Wait 5 seconds
Read count A = 0
Read count B = 0
Remove A->B replication (database counta->countb)
Set count A = 1
Set count B = 2
Wait 5 seconds
Read count A = 1
Read count B = 2
Create B->A replication (database countb->counta) (Creates an expected conflict)
Wait 5 seconds
Read/Merge count A = 2 (Conflict merged 2 revisions - Value = 2 wins)
Read/Merge count B = 2 (Conflict just handled and merged by Read A so nothing to do here)
Wait 5 seconds
Read count A = 2
Read count B = 2
Done - Loop

Expected Behaviour
It should continue working...
Your Environment
{
"couchdb": "Welcome",
"version": "2.3.0",
"git_sha": "07ea0c7",
"uuid": "2ad85a5174df9414fe1ff9a03db94bd3",
"features": [
"pluggable-storage-engines",
"scheduler"
],
"vendor": {
"name": "The Apache Software Foundation"
}
}

CouchDB Version used:
Browser name and version:
Operating System and version:

Additional context
See attached log file...
CouchDbReplicatorCrash.log

Closing comment (2019-03-16T00:42:42Z): This is a duplicate of #1810.
You need to upgrade to CouchDB 2.3.1.