[Date Prev][Date Next] [Chronological] [Thread] [Top]

running out of sockets in a long lived LDAP Client process using C SDK 3.0



Greeting,
First, I am cross posting this to OpenLDAP, Netscape and Mozilla as the
code that I will be talking about is the same.

We have a process which has a pool of connections to the LDAP server. At
any instant there will be a max of 30 connections.
The Netscape LDAP server 4.0 has an idletimeout of 120 seconds.

The client was getting LOCAL_ERROR after about 2 hours. The only way to
get around the problem was to restart
the client. Further investigation, by using the mozilla SDK instead of
the ldapssl30.so from Netscape revealed that
this was happening when trying to open a new connection.
[socket(.......)]

We also determined that ldap_unbind_s() calls nsldapi_free_connection(),

but this does *not* call nsldapi_close_connection() on a dead
connection.

There are lot of dead connections during the night, when there is not
enough activity
and the server closes the idle connections, but not the client. To the
client it is just a dead connection.

By closing the connection irrespective of the fact whether it was dead
or not seems to fix the problem.
Personally I think, checking and sending the unbind request is fair, but
we will have to close the socket anyway.

We are using the reconnect option. Tests were done with reconnect option
"on" and "off". Code changes were done
accordingly.

As a side note, we did not have this problem with  1.0
Here is the diff of the file request.c

520c520,521
<                       nsldapi_close_connection( ld, lc->lconn_sb );
---
>                       // resource problem occurs when closing here
>                       //nsldapi_close_connection( ld, lc->lconn_sb );
521a523,525
>               // close the connection anyway
>               nsldapi_close_connection( ld, lc->lconn_sb );
>

The snippet of code for clarity

*************************************************************
        if ( force || --lc->lconn_refcnt <= 0 ) {
                if ( lc->lconn_status == LDAP_CONNST_CONNECTED ) {
                        nsldapi_mark_select_clear( ld, lc->lconn_sb );
                        if ( unbind ) {
                                nsldapi_send_unbind( ld, lc->lconn_sb );

                        }
                        // resource problem occurs when closing here
                        //nsldapi_close_connection( ld, lc->lconn_sb );
                }
                // close the connection anyway
                nsldapi_close_connection( ld, lc->lconn_sb );


*************************************************************

Regards,
-Raj

begin:vcard 
n:Kunjithapadam;Raj
tel;cell:408-504-3254
tel;work:650-569-5733
x-mozilla-html:TRUE
org:@Home Network;Set Top Engineering
adr:;;4023 Budwing Terrace;Fremont;CA;94538;US
version:2.1
email;internet:rajk@home.com
title:Software Engineer
x-mozilla-cpt:;27456
fn:Raj Kunjithapadam
end:vcard