-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server down on freshly estabilshed connection #131
Comments
I'm currently looking into this. I have thus far not been able to see the problem for myself. Do you have a reproducible test case that seems to work? As an alternative, you could try using the LDAP SDK in synchronous mode rather than the default asynchronous mode. When run in synchronous mode, it doesn't maintain a separate listener thread per connection, which actually yields slightly better performance and less overhead, but you can't process asynchronous operations or use the same connection for multiple concurrent operations on separate threads. To use synchronous mode, create an LDAPConnectionOptions object, call setUseSynchronousMode(true) on that object, and then pass that object as an argument when creating the LDAPConnection object. |
I was not yet successful reproducing that problem with a smaller test. I changed our code to always use a fresh LDAPConnection and -since then- it is stable. Will it help you if I try to use synchronous mode? We are using async operations at some places and using new LDAPConnection objects all the time is an acceptable workaround. So I would only dare to try sync mode if that helps you somehow. |
Thanks for the update. It may well have something to do with the use of asynchronous operations, especially if there are still any outstanding operations in progress when attempting to close the connection. I'll continue looking into this. For now, your approach of simply creating a new connection object is probably the best one to use. There's no need to test with synchronous mode if you need asynchronous operations. |
When testing with asynchronous operations, I was able to reproduce an occasional failure every few thousand attempts or so. I've just committed a couple of changes, and with those changes in place, I've not been able to reproduce that failure. But if you've got the changes in place to use new connections rather than to keep using the same connection object, I'd recommend keeping the new behavior. |
I tested your commit from master with out old code again, unfortunately still I get the server down. Looking deeper at our code I can now say that we only use async*-operations at one special place with a dedicated connection. Its does not share |
I got the same error message and this is 100% replicable in my test case. The workaround is to establish a new LDAP connection, then everything works. @dirmgr I may have a chance to verify it if you can let me know how to set LDAP connection in synchronous mode. |
@totaljfb Could you describe your test case? Is it something that could be converted into a standalone program for testing? To use the LDAP SDK in synchronous mode, you need to use the LDAPConnectionOptions.setUseSynchronousMode method, and then provide that LDAPConnectionOptions object to the connection when creating it (or at least set it before the connection is established). For example:
|
@dirmgr Thank you. In my test case, the LDAPConnection is created at the beginning of the process, then it gets some user groups info from the LDAP Server, then it executes some other tasks and then uses the same connection object to retrieve some user info from the LDAP Server. It calls the LDAPConnection search funtion and errors happens right after that line. Unfortunately the I cannot replicate the issue today, everything is working. I will see if have another chance to test it in the furture. I have updated the code to use a new connection though. Thank you for your help! |
@totaljfb are you intentionally closing and re-establishing the connection at any point in the process, or are you just trying to continue using a connection that had previously been used and finding that it is no longer valid? If it's the latter, then that could be attributed to a few other things, like a networking issue or the server closing the connection after being idle for too long or after a maximum connection duration had been reached. In any case, I would actually recommend using a connection pool rather than an individual connection. Even if you only need one connection, using a connection pool can provide substantial benefits. Unlike a lot of APIs, a connection pool in the UnboundID LDAP SDK for Java can be used like an individual connection (for example, you can just call pool.search to perform a search on a pooled connection rather than manually checking out a connnection, issuing a search, and releasing the connection back to the pool). Doing this has several benefits, including:
|
@dirmgr The answer to your question, it's the latter. I just wanted to reuse the LDAPConenction object which was created at the beginning of the process. Your analysis of the root cause makes sense to me. And, thanks for the suggestion for using connection pool as a best practice, I appreciate it! |
Hi, we get the following error on an connection that has been freshly connected before:
This is part of our tests where we switch connections a lot between two servers. The
LDAPConnection
was used before on a completely different target system.Looking at the logs, to me there seems to be a race condition that the old
LDAPConnectionReader
is shut down after the new connection was established (I added some additional logs):Imho it is not to be guaranteed that LDAPConnectionReader.close will always wait for the thread shut down. If the shut down takes longer than 500ms, it will return anyway which could lead to this situation I suppose (That seems to be not the case here, but there at least it proves the point).
The text was updated successfully, but these errors were encountered: