GNOME Bugzilla – Bug 703297
remote socket closure during chunked write causes warning
Last modified: 2013-08-25 21:08:59 UTC
Created attachment 248041 [details] [review] soup-body-output-stream: Ignore write errors when closing the socket The bug is the following: 1. write in chunked mode 2. have the other side disconnect in the middle of writing a chunk 3. the write will fail 4. libsoup will try to close the iostream 5. inside the close_fn() it tries to call write_chunk() with buffer=NULL, this is not good solution: 1. ignore the buffer if it's NULL 2. Ignore any chunk writing errors in close, we're getting rid of the socket anyway I guess With patch Stack trace
+ Trace 232166
Comment on attachment 248041 [details] [review] soup-body-output-stream: Ignore write errors when closing the socket This isn't quite right. A chunked stream is terminated by a 0-length chunk, and that's what the call to soup_body_output_stream_write_chunked() in soup_body_output_stream_close_fn() is for. However, it was implicitly assuming that chunked_state was CHUNK_SIZE (in which case @buffer never gets looked at), which is what it would be in any non-error state. So what we want is to write the final chunk, with error-checking, if everything is OK, but skip that if not. I was going to say we could do that by checking if chunked_state was CHUNK_SIZE, but that's actually not quite right, because the write could return G_IO_ERROR_WOULD_BLOCK while it's in TRAILERS or DONE. Not that the code actually deals with that case correctly anyway. Ugh. OK, quick fix is to only do the final chunk write if state is CHUNK_SIZE when we call close_fn(). Does that fix it for you?
That would work I guess, that said, I think you should also ignore errors in calls to write_chunked() inside close_fn()
fixed in master (and eventually 2.43.91)