[Bsd-sharp-list] RE: Socket Connect and BeginConnect issues with threads

Tom McLaughlin tmclaugh at sdf.lonestar.org
Fri Mar 16 22:02:14 MDT 2007


On Fri, 2007-03-02 at 15:08 -0500, Robert Wojciechowski wrote:
> Created a bug at
> 
>   http://bugzilla.ximian.com/show_bug.cgi?id=81010
> 
> -- Robert

For both bugzillas you've entered I'm just waiting to see feedback from
the Novell side before committing.

tom

>  
> 
> > -----Original Message-----
> > From: Robert Wojciechowski 
> > Sent: Thursday, March 01, 2007 11:04 PM
> > To: bsd-sharp-list at forge.novell.com
> > Cc: 'Francisco Figueiredo Jr.'
> > Subject: Socket Connect and BeginConnect issues with threads
> > 
> > I have been working on a problem in the last few days related 
> > to threading and sockets on FreeBSD when I started noticing 
> > that a threaded database application that uses Npgsql would 
> > throw the following exception randomly (and not very 
> > frequently) when connecting to our PostgreSQL database at 
> > localhost:5432:
> > 
> >   Unhandled Exception: Npgsql.NpgsqlException:
> >   Socket is already connected
> >     at Npgsql.NpgsqlClosedState.Open (Npgsql.NpgsqlConnector 
> > context) [0x00000] 
> >     at Npgsql.NpgsqlConnector.Open () [0x00000] 
> >     at Npgsql.NpgsqlConnectorPool.GetPooledConnector 
> > (Npgsql.NpgsqlConnection Connection) [0x00000] 
> >     ...snip...
> > 
> > Npgsql uses Socket.BeginConnect to establish a connection to 
> > PostgreSQL (in the latest SVN), but why would I get an 
> > EISCONN from Socket.BeginConnect? I tried reverting to a 
> > blocking Socket.Connect call but it still happened once in a 
> > while. After researching further, things started to point 
> > towards the Mono win32 compatibility layer and the 
> > _wapi_connect method in io-layer/sockets.c, not my threaded 
> > application or Npgsql.
> > 
> > It seems I'm getting the EISCONN errno back from connect() as 
> > it runs in a do/while loop. The first call must not succeed 
> > for whatever reason (EINTR from a signal?) and the second one 
> > gives EISCONN which mono throws back up as an error because 
> > it doesn't know how to handle it.
> > 
> > The first patch attached checks the errno for EISCONN and 
> > treats it as a success. That seemed to still throw exceptions 
> > throughout the day, though. The second patch should be a 
> > little more robust -- it has been adapted from the following page:
> > 
> >   http://www.madore.org/~david/computers/connect-intr.html
> > 
> > I'm testing that out right now on my server. It's hard to 
> > trace down because I don't have a test case that causes this 
> > behavior... I just have to wait for it to happen again until 
> > I can create one.
> > 
> > I also wonder if this problem is related to bug #80839, a 
> > problem with Socket.BeginConnect on Solaris. Hmm!
> > 
> > Anyone have any ideas if I'm on the right path to fixing this problem?
> > 
> > -- Robert
> _______________________________________________
> Bsd-sharp-list mailing list
> Bsd-sharp-list at forge.novell.com
> 
> Home Page: http://www.mono-project.com/Mono:FreeBSD
> Project Site: http://forge.novell.com/mailman/listinfo/bsd-sharp-list
> IRC: #BSD-Sharp on irc.freenode.org
-- 
| tmclaugh at sdf.lonestar.org             tmclaugh at FreeBSD.org |
| FreeBSD                                   http://www.FreeBSD.org |
| BSD#                    http://www.mono-project.com/Mono:FreeBSD |



More information about the Bsd-sharp-list mailing list