Bug 35969 - Novell.Directory.Ldap.LdapConnection Thread stuck in loop, connection time-out
Summary: Novell.Directory.Ldap.LdapConnection Thread stuck in loop, connection time-out
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: General ()
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-11-17 22:11 UTC by Shane van Wyk
Modified: 2016-02-03 01:33 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Unit Test for time out (479 bytes, text/x-csharp)
2016-01-26 00:08 UTC, Shane van Wyk
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Shane van Wyk 2015-11-17 22:11:21 UTC
We Upgraded to Mono 4.2.1.102 Stable today and then discovered our LDAP connection stopped working.


We call: 

    LdapConnection ldapConnection = new LdapConnection();

    ldapConnection.Connect (host, port);


Which executes this line: Novell.Directory.Ldap.LdapConnection.cs

    
    public virtual void  Connect(System.String host, int port)
    {
        ...
        conn.connect(address, specifiedPort); // <--- Goes in here
        ...
    }

That then calls this line: Novell.Directory.Ldap.Connection.cs

    internal void  connect(System.String host, int port)
    {
	connect(host, port, 0); // <-- Then here
	return ;
    }

    private void  connect(System.String host, int port, int semaphoreId)
    {
        ...
        this.startReader(); // <-- In here Line 823
        ...
    }

    internal void  startReader()
	{
		// Start Reader Thread
		Thread r = new Thread(new ThreadStart(new ReaderThread(this).Run));
		r.IsBackground = true; // If the last thread running, allow exit.
		r.Start();
		waitForReader(r); // <-- There is a loop in here that it get stuck on.
		return ;
	}

It looks like it can't find the thread or something. It just gets stuck and then eventually the website times out.

Any Ideas?
Comment 1 Rodrigo Kumpera 2015-11-27 18:15:14 UTC
Hi Shane,

Can't say much, it might be due to integrating a lot of library code from microsoft or other internal changes in mono.

If you manage to extract a test case that shows the behavior, we'll gladly take a look at it.
Comment 2 Marc Van Laer 2016-01-02 20:34:55 UTC
We ran into the same issue this morning.

We are using the same - more or like - logic inside some of our websites as well.

We have a library build around this one which gives the same issues when running inside  a website logic (httpd on Centos 7) but this is not happening when the same library is used within a stand alone mono .exe which is used as a crontab daemon on the same machine !

Marc
Comment 3 Rodrigo Kumpera 2016-01-04 20:47:59 UTC
Hi Marc,

Can you provide a test case of sorts on this issue?

A good way to do it, given this is a non-core assembly, what you could do is grab the source from here[1] and build it as a regular part of your application. This should make it easy to understand the issue and figure out what's wrong.



[1] https://github.com/mono/mono/tree/master/mcs/class/Novell.Directory.Ldap
Comment 4 Shane van Wyk 2016-01-25 23:08:33 UTC
I pulled the code down and ran a debugger through it.

It is stuck on Novell.Directory.Ldap.Connection.waitForReader(System.Threading.Thread thread)

Not sure how to UnitTest this as that is a private Method.

Here is part of the StackTrace:

Novell.Directory.Ldap.Connection.waitForReader(System.Threading.Thread thread) in /home/XXX/Development/Novell.Directory.Ldap/Novell.Directory.Ldap/Connection.cs:578
Novell.Directory.Ldap.Connection.startReader() in /home/XXX/Development/Novell.Directory.Ldap/Novell.Directory.Ldap/Connection.cs:1230
Novell.Directory.Ldap.Connection.connect(string host, int port, int semaphoreId) in /home/XXX/Development/Novell.Directory.Ldap/Novell.Directory.Ldap/Connection.cs:823
Novell.Directory.Ldap.Connection.connect(string host, int port) in /home/XXX/Development/Novell.Directory.Ldap/Novell.Directory.Ldap/Connection.cs:640
Novell.Directory.Ldap.LdapConnection.Connect(string host, int port) in /home/XXX/Development/Novell.Directory.Ldap/Novell.Directory.Ldap/LdapConnection.cs:179

It just keeps looping in that waitForReader.
Comment 5 Shane van Wyk 2016-01-26 00:08:14 UTC
Created attachment 14723 [details]
Unit Test for time out

Just need to enter an IP address and Port for your test LDAP server.

You can extend the timeout on the unit test and still won't work.
Comment 6 Shane van Wyk 2016-02-03 01:33:28 UTC
It looks like this issue has now been resolved in version 4.2.2.30. I have updated my mono and it started to work again all of a sudden.

I can only speculate that it might have had something to do with the threading stuff that got changed in the initial release of mono 4.2.