Node-ldapjs: client leak Half-closes sockets

Created on 22 Apr 2020  路  6Comments  路  Source: ldapjs/node-ldapjs

in client with node v10.19.0, each time client.unbind() is called or on errors, the socket isn't destroyed only socket.end() is called and leak an Half-closes socket.

# lsof | grep "can't identify protocol"
node      25454     root   23u     sock                0,6        0t0  773832799 can't identify protocol
node      25454     root   24u     sock                0,6        0t0  773840655 can't identify protocol
node      25456     root   23u     sock                0,6        0t0  773831258 can't identify protocol
node      25456     root   24u     sock                0,6        0t0  773831259 can't identify protocol
node      25456     root   25u     sock                0,6        0t0  773831938 can't identify protocol
node      25456     root   26u     sock                0,6        0t0  773831939 can't identify protocol
node      25456     root   27u     sock                0,6        0t0  773832361 can't identify protocol
node      25456     root   28u     sock                0,6        0t0  773832362 can't identify protocol
node      25456     root   29u     sock                0,6        0t0  773832913 can't identify protocol
node      25456     root   30u     sock                0,6        0t0  773832914 can't identify protocol
node      25456     root   31u     sock                0,6        0t0  773834034 can't identify protocol

after some time, node can't open any file and return error EMFILE: too many open files, open

replace socket.end() by socket.destroy() in lines:
https://github.com/ldapjs/node-ldapjs/blob/master/lib/client/client.js#L1096
https://github.com/ldapjs/node-ldapjs/blob/master/lib/client/client.js#L1163
https://github.com/ldapjs/node-ldapjs/blob/master/lib/client/client.js#L1177
https://github.com/ldapjs/node-ldapjs/blob/master/lib/client/client.js#L1454
solved the problem

Most helpful comment

We're also seeing this behavior.
ldapjs-1.0.2
On node 12.13.1

Note I cannot reproduce this on my local MacOS environment. We only see it in our dockerized production environments.

We are connecting via secure (ldaps) to an Active Directory server.

All 6 comments

You have linked to code on the master branch. Are you seeing this issue on the next branch?

@jsumners i didn't test this branch but as it's the same socket.end() this should be the same result accordind to the nodejs documentation https://nodejs.org/api/net.html#net_socket_end_data_encoding_callback
vs
https://nodejs.org/api/net.html#net_socket_destroy_error

socket.end() is used so that the communication can complete.

@jsumners could the socket be destroyed once this is done or after some timout ?

Very likely. It would take some research into how the socket is being leaked so that it can be reaped correctly.

We're also seeing this behavior.
ldapjs-1.0.2
On node 12.13.1

Note I cannot reproduce this on my local MacOS environment. We only see it in our dockerized production environments.

We are connecting via secure (ldaps) to an Active Directory server.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abarik1981 picture abarik1981  路  4Comments

phi1ipp picture phi1ipp  路  4Comments

ivanhuay picture ivanhuay  路  5Comments

RaymondLC92 picture RaymondLC92  路  5Comments

ifroz picture ifroz  路  8Comments