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 741707 - Gsocket blocks trying to send data
Gsocket blocks trying to send data
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.40.x
Other Windows
: Normal major
: ---
Assigned To: gtkdev
gtkdev
: 732439 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2014-12-18 12:03 UTC by Ignacio Casal Quinteiro (nacho)
Modified: 2015-01-17 14:12 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
client (1.83 KB, text/x-csrc)
2014-12-18 12:04 UTC, Ignacio Casal Quinteiro (nacho)
  Details
server (2.89 KB, text/x-csrc)
2014-12-18 12:04 UTC, Ignacio Casal Quinteiro (nacho)
  Details
client (1.35 KB, text/x-csrc)
2014-12-18 12:28 UTC, Ignacio Casal Quinteiro (nacho)
  Details
server (2.34 KB, text/x-csrc)
2014-12-18 12:29 UTC, Ignacio Casal Quinteiro (nacho)
  Details
gsocket: block when errno says it will block (6.83 KB, patch)
2014-12-22 15:49 UTC, Ignacio Casal Quinteiro (nacho)
none Details | Review
gsocket: block when errno says it will block (6.83 KB, patch)
2014-12-22 15:55 UTC, Ignacio Casal Quinteiro (nacho)
none Details | Review
gsocket: block when errno says it will block (7.64 KB, patch)
2014-12-22 15:58 UTC, Ignacio Casal Quinteiro (nacho)
reviewed Details | Review
testcase for the bug (3.84 KB, patch)
2015-01-10 14:37 UTC, Paolo Borelli
committed Details | Review
patch (7.76 KB, patch)
2015-01-10 14:39 UTC, Paolo Borelli
committed Details | Review

Description Ignacio Casal Quinteiro (nacho) 2014-12-18 12:03:48 UTC
I am attaching on the next message a couple of programs (client, server) showing the problem.
Comment 1 Ignacio Casal Quinteiro (nacho) 2014-12-18 12:04:19 UTC
Created attachment 292973 [details]
client

The client program
Comment 2 Ignacio Casal Quinteiro (nacho) 2014-12-18 12:04:36 UTC
Created attachment 292974 [details]
server

The server program
Comment 3 Ignacio Casal Quinteiro (nacho) 2014-12-18 12:07:29 UTC
Basically the problem is that if you get the fd from a socket that already sent and received some data. Then you create a gsocket out of it and you try to send something then the socket send blocks forever.

If you try to do the same without sending or writing anything before you create the new gsocket out of the fd, then it works.

This test seems to work fine on linux but as pointed out it fails on windows. I've been checking the code of gsocket and couldn't see anything specific. The problem seems to be a blocking issue on the line:

https://git.gnome.org/browse/glib/tree/gio/gsocket.c#n2781
Comment 4 Ignacio Casal Quinteiro (nacho) 2014-12-18 12:28:41 UTC
Created attachment 292975 [details]
client

A bit smaller test
Comment 5 Ignacio Casal Quinteiro (nacho) 2014-12-18 12:29:01 UTC
Created attachment 292976 [details]
server

A bit smaller test
Comment 6 Ignacio Casal Quinteiro (nacho) 2014-12-22 15:49:24 UTC
Created attachment 293188 [details] [review]
gsocket: block when errno says it will block

On windows it may happen we recreate a gsocket
out of a fd from another gsocket that already
got the FD_WRITE event. If this happens in order
to get another FD_WRITE we need to have tried an
operation that might need such event. What we do
here is to first try to do the operation and
then if errno specifies that we might block then
wait for that event to occur.
Comment 7 Ignacio Casal Quinteiro (nacho) 2014-12-22 15:55:17 UTC
Created attachment 293189 [details] [review]
gsocket: block when errno says it will block

On windows it may happen we recreate a gsocket
out of a fd from another gsocket that already
got the FD_WRITE event. If this happens in order
to get another FD_WRITE we need to have tried an
operation that might need such event. What we do
here is to first try to do the operation and
then if errno specifies that we might block then
wait for that event to occur.
Comment 8 Ignacio Casal Quinteiro (nacho) 2014-12-22 15:58:03 UTC
Created attachment 293190 [details] [review]
gsocket: block when errno says it will block

On windows it may happen we recreate a gsocket
out of a fd from another gsocket that already
got the FD_WRITE event. If this happens in order
to get another FD_WRITE we need to have tried an
operation that might need such event. What we do
here is to first try to do the operation and
then if errno specifies that we might block then
wait for that event to occur.
Comment 9 Dan Winship 2015-01-07 20:20:00 UTC
Comment on attachment 293190 [details] [review]
gsocket: block when errno says it will block

>Subject: [PATCH] gsocket: block when errno says it will block

I don't think that describes what the patch is doing very well...

Also, maybe the commit body could be updated to mention that this is an optimization on unix too, as per bug 732439.

I'm assuming that you've verified that "make check" still passes on linux with this patch, and that running the tests by hand on windows, you get no new failures.

You should add a test case to gio/tests/socket.c that fails without this patch and succeeds with it. (It's OK if the test is Windows-specific if that's the easiest way to reproduce the bug.)
Comment 10 Paolo Borelli 2015-01-10 14:37:57 UTC
Created attachment 294225 [details] [review]
testcase for the bug

This testcase hangs on win32 without the patch and passes after the patch.
It also passes on linux (with and without the patch)

Incidentally maybe it would not be bad to have a portable g_dup (for now I included a static version in the testcase)
Comment 11 Paolo Borelli 2015-01-10 14:39:14 UTC
Created attachment 294226 [details] [review]
patch

Nacho's patch with the reworded commit message since nacho is currently on vacation
Comment 12 Dan Winship 2015-01-17 13:25:02 UTC
Comment on attachment 294225 [details] [review]
testcase for the bug

good, except:

>+  client = g_socket_new (G_SOCKET_FAMILY_IPV4,
>+			 G_SOCKET_TYPE_STREAM,
>+			 G_SOCKET_PROTOCOL_DEFAULT,
>+			 &error);

change those tabs to spaces please
Comment 13 Paolo Borelli 2015-01-17 14:05:59 UTC
Comment on attachment 294225 [details] [review]
testcase for the bug

amended as suggested and pushed
Comment 14 Paolo Borelli 2015-01-17 14:07:28 UTC
I'd like to cherry-pick these on stable, unless you think they are too risky.
Comment 15 Paolo Borelli 2015-01-17 14:08:58 UTC
*** Bug 732439 has been marked as a duplicate of this bug. ***
Comment 16 Dan Winship 2015-01-17 14:12:59 UTC
(In reply to comment #14)
> I'd like to cherry-pick these on stable, unless you think they are too risky.

sure (though maybe wait until it's gotten a bit of testing on master)