Skip to content

Find a way to avoid infinit loop Timeout #5

@Mumeii

Description

@Mumeii

Whenever debugging my code, I've noticed that the following code block from TcpConnectionPool.js can trigger an infinite "self called" setTimeout loop :

    realSend(message) {
        const self = this;
        if(this.connected === true) {
            this.connection.write(message)
        } else {
            const timeout = setTimeout(() => {
                self.realSend(message);
                clearTimeout(timeout);
            }, this.connectionNotReadyRetryInterval);
        }

    }

I guess it can occur in edge case situations (maybe due to debugging) when :

  • the connexion is not yet established whenever the realSend is called first
  • but it fails to be established after the first Timeout is setup, and thus, the self.connected = true; lamda in the TcpConnectionWrapper will never be triggered, and the loop will goes on forever

Calling the destroy method should raise a flag or a notification, a way or another, that could either break the Timeout loop, or even better, break it AND retry to establish a connection to send the message

Can't imagine (yet ?) a scenario that could trigger this case in production (I.E. without debugging interfering), but I feel like it would be much better been conservative and manage this potential bug anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions