Ldapjs - writing after end error

I created an authentication service using the following code in Node.js and ldapjs.

var when = require ('when');
var AuthenticationError = require('../errors/AuthenticationError');
var SessionManagerService = require('./SessionManagerService');

var ldap = require('ldapjs');

var client = ldap.createClient({
    url: 'ldaps://ad.mycompany.com:636',
    tlsOptions: {'rejectUnauthorized': false}

module.exports = {

    signIn: function (email, password) {
        return this.ldapBind(email, password).then(
            function () {
                return SessionManagerService.createSessionHash({email: email});

    ldapBind: function (email, password) {
        var deferred = when.defer();
        client.bind(email, password, function(err) {
            if (err) {
                deferred.reject (new AuthenticationError('Invalid username and/or password!', 'Authentication.signIn.error'));
            } else {
        return deferred.promise;



When I authenticate my user for the first time, it works fine, but it doesn't work starting on the second try. Error message: "write after end" .

When I restart the node server, it works again for the first try.

It looks like something is hanging, but I don't know what. Any idea?


source to share

1 answer

I solved this problem a few days ago to create an ldap client every time in the ldapBind function (in your case).



All Articles