Curl connection to cloud is closed with error: curl: (18) transfer closed with outstanding read data remaining


#1

I am reading a stream of server sent events from the particle cloud using
curl. I keep curl running continuously reading the event stream and writing the data
through a pipe to another process. This worked fine for several months but
sometime in the last few weeks it started failing every hour or two. Curl quits
with the error:
curl: (18) transfer closed with outstanding read data remaining.

My connection to the cloud is broken and must be restarted.

My curl command is:
curl --no-buffer --silent --show-error
https://api.particle.io/v1/devices/$KEY/events?access_token=$ACCESS_TOKEN
>> $PIPE 2>> $LOGFILE &

I read on StackOverflow that the problem was the server was not sending
the correct content length header and suggested I add:
-H ‘Expect:’ -H
to the curl command to suppress the Expect header by giving it an empty value.
It didn’t help.

Another suggestion was there was a timeout and I should add:
-H ‘Connection: keep-alive’ --keepalive-time 2
to my curl command but that didn’t help either.

Any one else see this problem and find a solution?

Thanks.