[Mono-bugs] [Bug 81010][Maj] New - Socket.Connect/BeginConnect "Socket is already connected" exception on FreeBSD

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Mar 2 16:30:55 EST 2007


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by robertw at ssgx.com.

http://bugzilla.ximian.com/show_bug.cgi?id=81010

--- shadow/81010	2007-03-02 16:30:55.000000000 -0500
+++ shadow/81010.tmp.17560	2007-03-02 16:30:55.000000000 -0500
@@ -0,0 +1,76 @@
+Bug#: 81010
+Product: Mono: Runtime
+Version: 1.2
+OS: other
+OS Details: FreeBSD 6.2-STABLE amd64
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: io-layer
+AssignedTo: dick at ximian.com                            
+ReportedBy: robertw at ssgx.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Socket.Connect/BeginConnect "Socket is already connected" exception on FreeBSD
+
+Description of Problem:
+
+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?
+
+Steps to reproduce the problem:
+In a multi-threaded application, try to connect to sockets while doing
+other work. 
+
+Actual Results:
+Exception in thrown for EISCONN.
+
+Expected Results:
+Connect without an exception.
+
+How often does this happen? 
+One out of every few executions.


More information about the mono-bugs mailing list