After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 688974 - g_pollable_output_stream_write_nonblocking on SoupBodyOutputStream can block when using chunked transfer encoding
g_pollable_output_stream_write_nonblocking on SoupBodyOutputStream can block ...
Status: RESOLVED FIXED
Product: libsoup
Classification: Core
Component: API
2.40.x
Other Linux
: Normal normal
: ---
Assigned To: libsoup-maint@gnome.bugs
libsoup-maint@gnome.bugs
Depends on:
Blocks:
 
 
Reported: 2012-11-24 13:48 UTC by Milan Plzik
Modified: 2012-12-12 09:55 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
soup-body-output-stream: fix non-blocking writing (4.84 KB, patch)
2012-11-26 22:27 UTC, Dan Winship
committed Details | Review

Description Milan Plzik 2012-11-24 13:48:33 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.
Comment 1 Dan Winship 2012-11-26 22:27:59 UTC
Created attachment 229953 [details] [review]
soup-body-output-stream: fix non-blocking writing

does this patch fix things for you?
Comment 2 Dan Winship 2012-12-12 09:55:53 UTC
Attachment 229953 [details] pushed as 6c53930 - soup-body-output-stream: fix non-blocking writing