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

Request timeout still triggered after an abandon, causing an uncaughtException #931

Open
glickel opened this issue Aug 11, 2023 · 1 comment

Comments

@glickel
Copy link

glickel commented Aug 11, 2023

Hello,
I have an uncaughtException if I'm using the abandon with a client configured with a timeout.

Could you confirm if it's a bug or if it's just me wrongly using the client please?
And if it's a bug, could you fix it please?

Here is a an example:

const { createClient, EqualityFilter } = require('ldapjs');

const client = new createClient({
    url: '...',
    timeout: 2000,
});

process.on('uncaughtException', (error) => {
    console.log('Uncaught exception happened', error);

    client.unbind();
});

client.once('connect', () => {
    client.bind('...', '...', (bindError) => {
        if (bindError) {
            console.error('bind error', bindError);
            return;
        }

        client.search(
            '...',
            {
                attributes: ['member'],
                filter: new EqualityFilter({ attribute: 'objectClass', value: 'groupOfNames' }),
                sizeLimit: 100000,
            },
            (searchError, result) => {
                if (searchError) {
                    console.error('search error', searchError);
                    return;
                }

                let messageId;

                result.on('error', (listenerError) => {
                    console.error('listener error', listenerError);
                });

                result.on('searchRequest', (message) => {
                    messageId = message.messageId;
                });

                setTimeout(() => {
                    if (messageId !== undefined) {
                        client.abandon(messageId, () => {
                            console.log('Abandon done', messageId);
                        });
                    }
                }, 100);
            },
        );
    });
});

client.on('error', (error) => {
    console.error('client error', error);
});

It's causing this output:

Abandon done 2
Uncaught exception happened TypeError: Cannot destructure property 'callback' of 'tracker.fetch(...)' as it is null.
    at Timeout.onRequestTimeout [as _onTimeout] (/some/anonymized/path/node_modules/ldapjs/lib/client/client.js:1280:23)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7)
@jsumners
Copy link
Member

It looks to me like you are attempting to send an abandon message for a request that has already been completed. Would you like to send a pull request to address this issue? Please remember to include unit tests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

2 participants