Kitura/Kitura-net

Error=Parsed fewer bytes than were passed to the HTTP parser

Opened this issue · 5 comments

Hi guys,

I have a very strange problem with my Kitura app. The problem occurs when fetching data from my Cloudant DB with the queryByView function from Kitura-CouchDB -> https://github.com/IBM-Swift/Kitura-CouchDB/blob/master/Sources/CouchDB/Database.swift#L295

I created the issue here because it seems like the problem is in this function -> https://github.com/IBM-Swift/Kitura-net/blob/master/Sources/KituraNet/ClientRequest.swift#L568

From the server logs I get this error message

[2019-11-12T20:19:47.420Z] [ERROR] [ClientRequest.swift:531 end(close:)] ClientRequest error. Failed to parse response. Error=Parsed fewer bytes than were passed to the HTTP parser

The CouchDB request looks like this ->

curl -H "Authorization: Bearer AUTH_TOKEN" --globoff "https://2551a1eb-7c0f-41ba-b250-a43a534327ad-bluemix.cloudant.com/my_database/_design/boxes/_view/events?startkey=[\"3B6EC126-7C3B-4E7D-A900-E47A7D7771AC\",\"2019-11-08T15:52:07.432+0000\"]&endkey=[\"3B6EC126-7C3B-4E7D-A900-E47A7D7771AC\",\"2019-11-08T22:37:05.931+0000\"]&include_docs=true" -X GET

So the strange thing about that issue is that it only occurs when the requested CouchDB Document is a bit bigger (for example around 47729 chars). For a small doc (for example around 3000 chars) it works. And to make confusion perfect, it only occurs when running the app as an Cloud Foundry-App and not when running it locally. Locally everything is fine.

Do you have any idea what is going wrong here? I am slowly despairing...

Best
Marcel

FYI -> I have an answer from the ibm cloud slack community

Hi,
the answere is sloppy because I don’t have time at the moment, but just not not leave you hanging, because its no fun, the short version is:
CouchDB repository you are using uses curl that has a bug on the linux version you are using hence it’s failing, I think.
To work around you can use different linux version I suppose if you have that kind of control over it and if not the workaround has been to use Kitura NIO that does not use curl.
But if you don’t have control over linux because you are using CloudFoundry then Kitura NIO will not deploy due to out of space error.
To solve it you need to disable the build dir cache. You can read about how to enable NIO and disable Cache here:
https://github.com/IBM-Swift/swift-buildpack#caching-of-the-build-directory
Unfortunatley that doesn’t work either with latest Swift so in that case we are out of luck.
Hope I didn’t lie about anything, it’s late and I need to run, but you can read more about it in the #ibm-cloud channel

Today I encountered the same problem on my own Kitura-net Fork. The only workaround for now was to specify HTTP 1.0 instead of HTTP 1.1 because HTTP 1.0 does not return chunked format.

I know this is only a temporary solution, but it works for me currently (still in development, not in production)

Commit:
https://github.com/geertberkers/Kitura-net/blob/2760af18ed972d05b17bbfbe079734fd403bce58/Sources/KituraNet/ClientRequest.swift#L699

Note:
This depends on an older version of Kitura-net, but I added a lot more information to specify Client Certificate information, the selected line is everything you need to change the HTTP Version

I will definitely try it! I have still no other solution for this.

I had this issue a while back too. The same error message. My solution was to use Ubuntu 16.04. I ran into this issue on Ubuntu 18.04. I am still working on Ubuntu 16.04 so not sure if the issue still occurs with 18.04. Another reference to this issue is: #312

I had the same problem. I exported the KITURA_NIO=1 as suggested in this post and started using NIO package instead of Kitura net package. That picks the correct version of curl libs i guess.