Multithreaded accept/connect locks

wtk25@drexel.edu wtk25@drexel.edu
Thu Jun 28 20:17:00 GMT 2007


On Jun 27 19:08, Corinna Vinschen wrote:
> Yes, that's the same problem.  From stracing the 
> problem it appears that the underlying problem is
> in WinSock.  connect returns with an error 10036,
> WSAEINPROGRESS, because the other thread is at 
> that time executing a blocking socket call 
> (accept).  The problem is aggravated by the fact
> that the connect call in Cygwin is always using 
> non-blocking mode and WSAEINPROGRESS is also 
> referring to a connect which is still in progress
> and needs further handling.

With the 's' option, my previous program blocked on select() instead of accept(), so connect() must also collide with select().

> In CVS, the Cygwin socket code has been reworked a 
> lot.  One important change is that besides 
> recv/send/connect also accept is now implemented
> in non-blocking mode under the hood.  This has the 
> effect that the connect call should't be able to 
> fail due to a blocking accept in the same process.
> If you try your application against a recent 
> snapshot from http://cygwin.com/snapshots/, your 
> test application will run as expected.

I'd like to keep this in a standard Cygwin distribution if possible.

> However, if you want the application to work with > 1.5.24 as well, you should consider to implement 
> accept in non-blocking mode manually in your 
> application.

I updated my test program to use nonblocking accepts using two methods, ioctl() and fcntl().  My results are attached in TESTS.  I've also attached my new test program, as well as all relevant stack traces.

Summary of the results:
 ccs3   failed to run every time.
 ccs3 i failed to run in alternate trials.  Very strange.

When I ran
 ccs3 i
by itself (not under strace), it failed every time.

Looking at the strace output:
 1) The socket non-blocking set completes successfully every time.
 2) The call to connect() still returns winsock error 10036, but I suppose we expect it to, since accept() hasn't happened yet.
 3) The difference between successful and failed runs seems to be whether some
 fhandler_socket...
 wndproc...
stuff happens before (bad) or after (good) some
 select_stuff::...
 socket_cleanup...
stuff, although there was no wndproc stuff after the fhandler_socket call near where
 ccs2 s
locked up...

Tomorrow I will try polling nonblocking connect()s and select()s (yuck :p), and if that fails, try out some newer snapshots.

Thanks for your help.

Trevor

-------------- next part --------------
A non-text attachment was scrubbed...
Name: check_cs3.c
Type: application/octet-stream
Size: 6576 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070628/c640285a/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tests
Type: application/octet-stream
Size: 8450 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070628/c640285a/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strace_ccs2_s.out
Type: application/octet-stream
Size: 46057 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070628/c640285a/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strace_ccs3.out
Type: application/octet-stream
Size: 44773 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070628/c640285a/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strace_ccs3_i.out
Type: application/octet-stream
Size: 54072 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070628/c640285a/attachment-0004.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strace_ccs3_i2.out
Type: application/octet-stream
Size: 45286 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070628/c640285a/attachment-0005.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strace_ccs3_i3.out
Type: application/octet-stream
Size: 53905 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070628/c640285a/attachment-0006.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strace_ccs3_i4.out
Type: application/octet-stream
Size: 45286 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070628/c640285a/attachment-0007.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strace_ccs3_i5.out
Type: application/octet-stream
Size: 54071 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070628/c640285a/attachment-0008.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strace_ccs3_6.out
Type: application/octet-stream
Size: 45622 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070628/c640285a/attachment-0009.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strace_ccs3_7.out
Type: application/octet-stream
Size: 44773 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20070628/c640285a/attachment-0010.obj>
-------------- next part --------------
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


More information about the Cygwin mailing list