GNOME Bugzilla – Bug 688974
g_pollable_output_stream_write_nonblocking on SoupBodyOutputStream can block when using chunked transfer encoding
Last modified: 2012-12-12 09:55:56 UTC
(this error was detected on libsoup-2.40.2, but to my best knowledge, the code did not change also in newer releases) g_pollable_output_stream_write_nonblocking relies on call to g_pollable_output_stream_is_writable and consecutive call to g_output_stream_write. This behavior is problematic when using chunked encoding, due to implmentation of soup_body_output_stream_write_chunked. If, when writing the chunk length or trailer data ('metadata' in following text), all bytes from the buffer can not be written, function loops and invokes g_write_output_stream again (without checking for write readiness), possibly blocking execution. To fix this issue, various paths might be taken: 1) Implement custom g_pollable_stream_write_nonblocking, which would properly return G_IO_ERROR_WOULD_BLOCK. This has side effect, that sometimes, even though is_writable call returns True, write_nonblocking still returns G_IO_ERROR_WOULD_BLOCK (as it is transparently writing chunk length or trailer to the now-available stream). 2) Fix is_writable for SoupBodyOutputStream, which should take into account not only stream writeability, but also state of writing metadata and transparently write them, whenever it is called. Neither of attepmts above is especially elegant, so I'm open for discussion.
Created attachment 229953 [details] [review] soup-body-output-stream: fix non-blocking writing does this patch fix things for you?
Attachment 229953 [details] pushed as 6c53930 - soup-body-output-stream: fix non-blocking writing