Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Anonymous_User Absent Member.
Absent Member.

Exceptions in Novell.Directory.Ldap.Connection.shutdown


I'm getting unhandled exceptions from calls to
LdapConnection.Disconnect() when setting when setting
connection.SecureSocketLayer = true and pointing the connection to an
open non-SSL LDAP port. There is currently a bug open with Novell on
this (opened by someone else), but, as Novell hasn't responded sine
1/14/2008, I thought I'd see if anyone on the mailing list has
experienced a similar issue or has any insight.

Here is the link to the bug report:

To paraphrase the bug report:

It seems that the shutdown() method in Connection.cs is not thread safe.
Calls to LdapConnection.Disconnect(), the dying
Connection.ReaderThread.Run(), and the Connection destructor all call
shutdown(). This leads to unhandled exceptions coming out of the Ldap

The Novell LDAP C# library comes with sample code. I've modified the
SSL code sample SecureBind.cs to illustrate the problem. Note that port
389 is an open but non-SSL port on my server. Also note that the
try-catch around the call to conn.Disconnect() will NOT catch the
exceptions in the shutdown() method because they are on a different
thread (at least for .net >= 2.0). Thus, these exceptions can bring the
whole app down.

static void Main(string[] args)

for (int i = 0; i < 100; i++)
LdapConnection conn=null;
conn= new LdapConnection();
Console.WriteLine(" SSL Bind Successfull");

catch(Exception e)
Console.WriteLine("Error:" + e.Message);

catch(Exception ex)
Console.WriteLine("Caught exception from
Console.WriteLine("Exception is: {0}", ex.Message);

The reason for the loop is that the problem does not happen every time,
just often. This is due to the threading nature of the problem.

Here is the exception that I get:

Exception is (sorry, had to manually type this):
Unhandled Exception: System.Net.Sockets.SocketException: The socket is not
at System.Net.Sockets.Socket.Shutdown (SocketShutdown how)
at Novell.Directory.Ldap.Connection.shutdown(System.String reason, Int32
semaphoreId, ...)
at Novell.Directory.Ldap.Connection+ReaderThread.Run()

Finally, here is how I've modified Connection.cs to get the above sample
code to succeed. This is approximately lines 1130-1160 of Connection.cs.

if (socket != null || sock != null)
// Just before closing the sockets, abort the reader thread
if ((reader != null) && (reason != "reader: thread stopping"))
// Close the socket
if(Ssl && sock != null)
if (sock.Connected)
else if (socket != null)
if(in_Renamed != null)

catch (System.Net.Sockets.SocketException)
// ignore problem closing socket
socket = null;
sock = null;

I do not think these changes solve the bug, the only mask it. The root
cause is that this method is not thread safe. I see this problem with
version 2.1.10 and 2.1.9 of the Novell LDAP library. I'm using Mono
1.2.6 on SLES 10.

Has anyone else seen a similar issue?
Labels (1)
1 Reply
Anonymous_User Absent Member.
Absent Member.

Re: Exceptions in Novell.Directory.Ldap.Connection.shutdown

I am experiencing exactly this issue at the moment with the same
version of the LDAP C# code. I presume it has never been fixed ? Do you
have a version of your modified code built ? I haven't managed to build
it from source yet. I could probably do so, but if you have a versio
nthat works.....

endacoe's Profile: http://forums.novell.com/member.php?userid=44974
View this thread: http://forums.novell.com/showthread.php?t=365094

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.