[ 
https://issues.apache.org/jira/browse/COUCHDB-2202?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14593373#comment-14593373
 ] 

Alexander Shorin commented on COUCHDB-2202:
-------------------------------------------

The problem was easily found with wireshark dump. The response for filtered 
changes feed request contained the following data:
{code}
d
{"results":[

HTTP/1.1 500 Internal Server Error
Server: CouchDB/1.6.1 (Erlang OTP/R16B02)
Date: Fri, 19 Jun 2015 10:52:51 GMT
Content-Type: application/json
Content-Length: 147
Cache-Control: must-revalidate
Access-Control-Expose-Headers: Cache-Control, Content-Type, Server
Access-Control-Allow-Origin: http://localhost:8100
Access-Control-Allow-Credentials: true

{"error":"compilation_error","reason":"Expression does not eval to a function. 
(function (doc) {\n return doc.type === \"login\";\n}.toString())"}
{code}

What's happened:
1. CouchDB initiated response with chunked transfer encoding
2. Then sent first chunk with "{"results":[" data
3. Then it started to apply filter function to each doc in stream. But before 
apply that function, CouchDB need to compile it on query server side
4. This compilation fails because of some error and query server report about 
it back to CouchDB
5. CouchDB has nothing to do with such error, but throw it forward
6. This triggers internal mechanisms to send a HTTP 500 Server Error response
7. But they have no idea that the response what already initiated
8. So HTTP status line and headers for error response just pushed to the socket
9. Browser expects chunked transfer encoding for the received data, what means 
that every chunk prefixed with it hexified length, but not our HTTP 500 response
10. Receiving HTTP 500 response data within active HTTP 200 response, browser 
detects that chunked transfer encoding is malformed and raise own 
net::ERR_INVALID_CHUNKED_ENCODING error, aborting the connection

In the end here are two issues:
1. CouchDB cannot make a correct report about any issues that causes filter 
function during the changes feed stream
2. In fact, the actual problem is in user land javascript code

So good fix is to fix the filter function in anycase. As for CouchDB, it should 
be also fixed in order to gracefully report about such issues without 
malforming active HTTP response.

> Replication fails with net::ERR_INVALID_CHUNKED_ENCODING
> --------------------------------------------------------
>
>                 Key: COUCHDB-2202
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-2202
>             Project: CouchDB
>          Issue Type: Bug
>      Security Level: public(Regular issues) 
>          Components: HTTP Interface
>            Reporter: Per Liedamn
>
> We're trying to replicate docs from a couchdb instance using a filter stored 
> in couch. If we do not specify a filter, everything works as expected but 
> when we specify a filter name, couch db responds with a truncated message 
> causing Chrome to show the following message in the console:
> {{GET 
> http://hostname:5984/ourdbname/_changes?style=all_docs&feed=longpoll…fromDate=2014-03-10T23:00:00.000Z&since=0&limit=25&_nonce=8PCzVQzOyrrhy1VB
>  net::ERR_INVALID_CHUNKED_ENCODING}}
> Here's the full URL for the request:
> {{http://hostname:5984/ourdbname/_changes?style=all_docs&feed=longpoll&filter=replication/filter&since=0&limit=25&_nonce=7NIrlLVhSxjf1FvY}}
> We were initially doing this via PouchDB's API, but testing the URL above 
> directly in the browser gives the same result.
> We also tested in Firefox, which does not show the error message about 
> chunked encoding, but gives a truncated JSON response (only part of a JSON 
> doc is shown).
> Tested with:
> * CouchDb 1.4.0 (Ubuntu)
> * CouchDb 1.5.0 (Windows)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to