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

CancellationToken doesn't cancel sending a message if offline #31

Open
StephenWilson opened this issue Jan 27, 2023 · 2 comments
Open

Comments

@StephenWilson
Copy link

I have noticed a case where it is possible to attempt to send a message using the SDK and not be able to cancel sending.
This happens when an internet connection is not available. I found repeated attempts to send the message are made based off network errors to Twilio services showing in the logs.
After attempting to use the CancellationToken provided by the MessageBuilder buildAndSend function, it does not cancel sending the message unless a connection has already been made by the SDK to start sending the message.

I would expect that when the CancellationToken cancel function is called and:

  1. there is no active connection sending the message data
  • no further attempts to send the message are made
  • the MessageBuilders buildAndSend closure would fire to inform the caller that it has been cancelled
  1. there is an active connection sending message data
  • the current process to send the message is cancelled
  • the MessageBuilders buildAndSend closure would fire to inform the caller that it has been cancelled

What actually happens when the CancellationToken cancel function is called and there is no active connection sending the message data:

  • further attempts to make a connection are made on a regular basis until an internet connection is available and the message sends
  • no callbacks to the closure passed to MessageBuilder buildAndSend for the repeated failed attempts to send.

As a side note, I don't actually want the behaviour where the Twilio SDK make repeated attempts to send a message while offline. A more useful function for us would be to attempt to send a message and callback with an error if there is a lack of internet availability without silent attempts to retry.

@Gray-Wind
Copy link
Contributor

Gray-Wind commented Feb 1, 2023

Hello,

Thank you for pointing this out! We are working on a re-designed internal system of handling network states and most of the issues would be solved there. I will pay an additional attention to the behaviour of the cancellation token in the offline case, it should work just as you described.

Also there is a case when a request has been sent but answer didn't come yet, cancelling of the message send process will actually do virtually nothing. The SDK doesn't remove message if it was already sent, it just cancels the pending request.

@berkus
Copy link
Contributor

berkus commented Nov 9, 2023

There should be a new framework in place in 4.x versions, it's unfinished but perhaps it does what you want already?

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

No branches or pull requests

3 participants