node-ldapauth-fork icon indicating copy to clipboard operation
node-ldapauth-fork copied to clipboard

[Bug] Randomly having "Error: Client network socket disconnected before secure TLS connection was established"

Open kopax opened this issue 6 years ago • 3 comments

description

We are using:

We have GItLab-CI runner that run npm install --registry https://our.registry.com for the project.

relevant log

I can connect repetitively multiple time to the LDAP, until:

In node 10.1.0

http <-- 200, user: me(172.18.0.1 via 172.16.14.10), req: 'GET /node-int64', bytes: 0/2481
 http --> 304, req: 'GET https://registry.npmjs.org/multicast-dns-service-types' (streaming)
 http --> 304, req: 'GET https://registry.npmjs.org/multicast-dns-service-types', bytes: 0/0
 debug--- connected after 1 attempt(s)
 debug--- connected after 1 attempt(s)
 debug--- connected after 1 attempt(s)
 debug--- failed to connect after 1 attempts
 fatal--- uncaught exception, please report this
Error: Client network socket disconnected before secure TLS connection was established
    at TLSSocket.onConnectEnd (_tls_wrap.js:1092:19)
    at Object.onceWrapper (events.js:273:13)
    at TLSSocket.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1086:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

In node 8.11.2

 info --> making request: 'GET https://registry.npmjs.org/array-unique'
 debug--- connected after 1 attempt(s)
 debug--- connected after 1 attempt(s)
 fatal--- uncaught exception, please report this
TypeError: (groups || []).concat is not a function
    at authenticatedUser (/usr/local/lib/node_modules/verdaccio/build/lib/auth.js:372:32)
    at /usr/local/lib/node_modules/verdaccio/build/lib/auth.js:105:26
    at sendResult (/usr/local/lib/node_modules/verdaccio-ldap/node_modules/ldapjs/lib/client/client.js:1395:12)
    at messageCallback (/usr/local/lib/node_modules/verdaccio-ldap/node_modules/ldapjs/lib/client/client.js:1421:16)
    at /usr/local/lib/node_modules/verdaccio-ldap/node_modules/ldapjs/lib/client/client.js:1282:14
    at Array.forEach (<anonymous>)
    at Client._onClose (/usr/local/lib/node_modules/verdaccio-ldap/node_modules/ldapjs/lib/client/client.js:1272:19)
    at Object.onceWrapper (events.js:272:13)
    at TLSSocket.emit (events.js:180:13)
    at _handle.close (net.js:541:12)
    at TCP.done [as _onclose] (_tls_wrap.js:379:7)

related sources

  • https://github.com/nodejs/node/issues/21088
  • https://github.com/Alexandre-io/verdaccio-ldap/issues/33

We can connect repetitively to the LDAP but then this error happens and prevent us totally from using our verdaccio registry.

Is there a way to prevent such bug ? The verdaccio-ldap plugin is not supporting starttls, using starttls ,

kopax avatar Jun 01 '18 23:06 kopax

I got the same problem

miaoihan avatar Jun 21 '18 09:06 miaoihan

I got the same problem using version 2.1.4 of passport-ldapauth package which uses node-ldapauth-fork version 4.3.2.

passport-ldapauth creates a new LdapAuth with starttls option and immediately call LdapAuth.prototype.authenticate (here).

It seems calling authenticate before node-ldapauth-fork has received the validation that the connection has been secured by ldapjs is also causing the error "Client network socket disconnected before secure TLS connection was established".

Maybe node-ldapauth-fork should not try to use any LDAP client before the connection has been secured while option starttls is set.

What do you think? Am I missing the point completely?

maxime-beguin avatar Apr 29 '20 08:04 maxime-beguin

Hi, my colleague and me have found a fix for this bug. We tried to fix it as little invasive as possible. I have created a pull request, with this fix it is not needed to change anything in the function calls, so packages which depend on this one will not have to change their code, just update the version as soon as this merge request gets accepted and new version released.

YuJin44 avatar Mar 23 '24 07:03 YuJin44