Skip to content

Add the ability to abort an initial connection attempt #327

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

Merged

Conversation

ethanlookpotts
Copy link
Contributor

I discovered this while working with an offline robot - if you're making your initial connection with retries, there was previously no ability to abort the reconnect attempts once they started. This allows the user to pass in an object with the rest of the dial options that they can later cancel.

Change log

  • Add reconnectAbort option to DialOpts
  • Do not retry if reconnectAbort.abort is true
  • Update vanilla example with usage

Tested

  • Vanilla example
  • Used in app, observed behavior is resolved!

@ethanlookpotts ethanlookpotts requested a review from a team as a code owner July 29, 2024 15:55
Copy link
Member

@njooma njooma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of questions:

  1. Why does it have to be an object? Can it not just be a boolean? Does it have something to do with reference semantics if it's an object?
  2. The connection logic returns a promise, right? Is there a way to have the cancellation of the promise work as the abort signal?

@ethanlookpotts
Copy link
Contributor Author

ethanlookpotts commented Jul 29, 2024

  1. Why does it have to be an object? Can it not just be a boolean? Does it have something to do with reference semantics if it's an object?

Exactly, we want the reference semantics of the object so that the connection can be cancelled later. Initially, the caller would set reconnectAbort.abort to false and then later decide to stop attempting reconnects and set to true.

  1. The connection logic returns a promise, right? Is there a way to have the cancellation of the promise work as the abort signal?

Unfortunately promises don't support cancel natively. The closest thing is you can use an AbortController with fetch but that doesn't help us with this vanilla promise - we would have to manually listen to the signal just like we're doing here.

@njooma
Copy link
Member

njooma commented Aug 2, 2024

@ethanlook Ok cool thanks for clarifying! Can we call it something like reconnectCancelSignal or reconnectAbortSignal or something? So that it's clear that setting the value will actually signal to the connection client that it should abort? Unless that goes against a TS naming convention

@ethanlookpotts
Copy link
Contributor Author

@njooma Happy to change the name! I chose this one because it matches the exponential-backoff parameter. reconnectAbortSignal sounds good to me!

@ethanlookpotts
Copy link
Contributor Author

@njooma renamed to reconnectAbortSignal: c8d93fb

@njooma njooma merged commit e24a564 into viamrobotics:main Aug 5, 2024
3 checks passed
@ethanlookpotts ethanlookpotts deleted the ethanlook/disconnect-cancel branch August 5, 2024 18:14
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

Successfully merging this pull request may close these issues.

2 participants