jetti777Ltd / mochiweb

Automatically exported from code.google.com/p/mochiweb
Other
0 stars 0 forks source link

Weird problems with chunks split into two gen_tcp:send() calls #16

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
We've been experiencing weird issues with responses using chunked encoding in 
the CouchDB 
project. The effect was that after processing a response using chunked 
encoding, Safari would 
sometimes send the next request twice, the second being a retry after the first 
failed (at the TCP 
packet level, not the HTTP level). It looked like the chunked response was 
leaving "garbage on the 
wire", which then corrupted the next response.

After much debugging and experimentation, the issue turned out to be caused by 
the way chunks 
are sent in mochiweb_response:write_chunk(). There's a call to gen_tcp:send() 
for the chunk 
boundary, and another gen_tcp:send() for the actual chunk content. Combining 
the two into a 
single call fixed the problem we were seeing.

I'm sorry I can't provide a better diagnosis of the error, as it's still 
somewhat mysterious to us. But 
the fix/workaround seems like a good idea in any case, so here's the patch.

Original issue reported on code.google.com by cmlenz on 28 Jul 2008 at 3:04

Attachments:

GoogleCodeExporter commented 8 years ago
applied in r83, thanks!

Original comment by bob.ippo...@gmail.com on 28 Jul 2008 at 3:54

GoogleCodeExporter commented 8 years ago
I'm really confused by this. Bob, any idea why the two calls would generate 
garbage on the wire?

Original comment by dre...@gmail.com on 18 Nov 2008 at 7:11

GoogleCodeExporter commented 8 years ago
Erlang bug? Hard to say, I wasn't the one that debugged it. I've never seen 
this happen myself.

Original comment by bob.ippo...@gmail.com on 18 Nov 2008 at 7:15