tediousjs/tedious-connection-pool

connection pool doesn't not respect request callback on socket error

ashelley opened this issue · 1 comments

Hello,

I've just reported a problem with tedious not calling the request callback when a socket error occurs.

tediousjs/tedious#324

However, If the above issue was fixed there is still a problem with how the connection pool deals with connection errors. currently in tedious on a socket error the error event gets emitted before it internally routes to the error state:

https://github.com/pekim/tedious/blob/master/src/connection.js#L485-L487

This means that the error handling in the connection pool will set the state to STATE.FINAL before the correct error handler is run. This is because the error handler of the connection pool calls .close() on the connection before the the error state has been routed to properly:

https://github.com/pekim/tedious-connection-pool/blob/master/lib/connection-pool.js#L81-L95

    var handleError = function(err) {
        self.log('connection closing because of error');

        connection.removeListener('end', endHandler);
        connection.close(); // <--- because the error event is emitted before the error state is routed this causes the error state always to route to STATE.FINAL

        pooled.status = RETRY;
        pooled.con = undefined;
        if (pooled.timeout)
            clearTimeout(pooled.timeout);

        pooled.timeout = setTimeout(createConnection.bind(self, pooled), self.retryDelay);

        self.emit('error', err);
    };

This issue may not matter except in the future if it's possible to get request callbacks in tedious when a socket error occurs. I just wanted to make note of this issue.

Hello I have created a pull request to address this issue:

#24