Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Invalidate Error #961

Open
Fray117 opened this issue Jan 5, 2024 · 0 comments
Open

Invalidate Error #961

Fray117 opened this issue Jan 5, 2024 · 0 comments

Comments

@Fray117
Copy link

Fray117 commented Jan 5, 2024

I think there issue it's a bit old on #873, but somehow I met a similar problems when I tried to write an helper (service) in NestJS.

This issue not came after every restart until it hit a certain interval.

My issue related to credentials validation to Microsoft AD which just went success whatever the password with just a correct dn.

AFAIK, other teams working with this AD were using php which only validate once and flush the client and I assumed with hanging connection like this on JS had some problems.

Minimal reproduction

First, I import Client and make an variable to containing the ldapjs client

import { Client, SearchEntry, createClient } from 'ldapjs'

export class LdapService implements OnApplicationBootstrap {
	private auth: Client
}

then I add function that run everytime the NestJS is started (or restart) to initiate the client

async onApplicationBootstrap() {
	const ldapOptions = {
		url: LDAP_URL,
		reconnect: true,
	}

	this.auth = createClient(ldapOptions)

	this.auth.on('connectError', (err) => {
		this.logger.warn(`Auth ${err}`)
	})

	this.auth.on('error', (err) => this.logger.error(`Auth ${err}`))
}

Finally I had an function to verify dn and password by bind

async authenticateLdap(dn, password): Promise <boolean> {
	return new Promise((resolve) => {
		this.auth.bind(dn, password, (err) => {
			if (err) {
				// Bind failed
				resolve(false)
			} else {
				// Bind was successful, immediately unbind for next user authentication
				this.auth.unbind()

				resolve(true)
			}
		})
	})
}

I tried to unbind immediately after it succesfully binded

However in about several minutes later it came an error Client Error: read ECONNRESET which returned by this listener

this.auth.on('error', (err) => this.logger.error(`Auth ${err}`))

Originally posted by @Fray117 in #873 (comment)

@Fray117 Fray117 changed the title I think this issue it's a bit old, but somehow I met a similar problems when I tried to write an helper (service) in NestJS. Invalidate Error Jan 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant