Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find a way to avoid infinit loop Timeout #5

Open
Mumeii opened this issue Aug 19, 2022 · 0 comments
Open

Find a way to avoid infinit loop Timeout #5

Mumeii opened this issue Aug 19, 2022 · 0 comments

Comments

@Mumeii
Copy link

Mumeii commented Aug 19, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant