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

[BUG] Updating token after signaling connection has gone offline causes Invalid State error #33

Closed
8 tasks done
aryo opened this issue Sep 2, 2021 · 15 comments
Closed
8 tasks done
Labels
bug Something isn't working jira added

Comments

@aryo
Copy link

aryo commented Sep 2, 2021

  • I have verified that the issue occurs with the latest twilio.js release and is not marked as a known issue in the CHANGELOG.md.
  • I reviewed the Common Issues and open GitHub issues and verified that this report represents a potentially new issue.
  • I verified that the Quickstart application works in my environment.
  • I am not sharing any Personally Identifiable Information (PII)
    or sensitive account information (API keys, credentials, etc.) when reporting this issue.

Code to reproduce the issue:

  1. Have successfully registered device
  2. Cause signaling connection to go offline (e.g. turn off wifi)
    • this sets device._shouldRegister to be true internally
  3. Reconnect, signaling connection goes connected again and device is registered again
  4. Any attempt to update device token will trigger signaling connected, which in turn internally calls register because _shouldRegister is true, and causes an Invalid State exception due to calling register while state is already registered.

Expected behavior:

Should not throw exception

Actual behavior:

Throws exception InvalidStateError: Attempt to register when device is in state "registered". Must be "unregistered".

Software versions:

  • Browser(s): Chrome 92.0.4515.159
  • Operating System: macOS
  • twilio.js: 2.0.1
  • Third-party libraries (e.g., Angular, React, etc.): React
@aryo aryo added the bug Something isn't working label Sep 2, 2021
@bojandurmic
Copy link

bojandurmic commented Oct 2, 2021

I am facing the same issue. It does not seem to affect app performance, only causes very ugly errors during development.

It thought I'd made a mistake in my code somewhere, even though I call device.register() only once, and I make sure to check device.state before doing that.

@ryan-rowland do you have any tips on how to avoid this error?

@aryo have you found the way to fix this or at least suppress the error? I am also not able to catch it with device.on('error').

@cmcaboy
Copy link

cmcaboy commented Jan 18, 2022

I am running into the same issue. We have been suppressing the error for now, but it is very annoying.

@ryan-rowland
Copy link
Contributor

Thanks for bringing this to our attention, and thanks @cmcaboy for pinging us again on this. I've created an internal ticket so that we can take a closer look at this.

@yashsavla9
Copy link

Any timeline by when this fix will be released ?

@PhilipTranP
Copy link

I faced the same issue when testing repeated calls/hangups. When call device.unregister() together with device.disconnectAll(), the error goes away. Hope it helps.

@nemes-zoltan
Copy link

nemes-zoltan commented May 17, 2023

@charliesantos we are also running into this issue here is a list of ways we managed to reproduce it:

"@twilio/voice-sdk": "^2.4.0"

Manual approach:

  1. Add a short TTL token, let it expire in the twilio device but dont refresh it
  2. wait until you see device fire event for unregistered state
  3. Now set a new token via updateToken, and then while you have an active token set another active token

Users machine goes into sleep state:

  1. Another way to reproduce it set a short TTL token (30 seconds for example)
  2. Put your PC to sleep and wait 30 seconds until token expires in sleep state
  3. Then Resume PC you will get the error

Users internet connection drops:

  1. Put a short TTL token and disconnect your ISP from your router
  2. Wait until token expires then reconnect ISP in the router
  3. When everything reconnects and twilio starts reconnecting you will get this error

I tested and adding this._shouldReRegister = false after this.register() (and waiting for promise to complete) seems to fix the issue

this.register();

Another problem is that since updateToken creates a promise inside and does not return it there is no way for us to know when token is updated successfully, if we are continuously trying to update token this can create a race condition as-well, would be nice to have promise returned.

For now a way to get around this issue for us was to check for this.device._shouldReRegister and unregister the device then call updateToken and after that wait until device._stream.status === 'ready' and then manually set device._shouldReRegister = false

@charliesantos
Copy link
Collaborator

Thanks @nemes-zoltan . This is helpful.

@aburkowsky9
Copy link

Is it not simple enough internally to check device state before attempting to re-register? I think most of your consumers do this in their apps to avoid this error. Id imagine its fairly simple to do the same check within the SDK.

@charliesantos
Copy link
Collaborator

@aburkowsky9 that's correct. This is currently within our radar and should be part of a future round of bug fixes.

@brightsider
Copy link

any updates for this?

@treycucco
Copy link

I recently upgraded from v1 to v2 of the SDK (2.8.0) and this error happens for us as well. It's easily reproducible in dev as others have stated by setting the token ttl to something short.

@nemes-zoltan
Copy link

@charliesantos when is it possible to get a fix for this issue?

@vasanthnathan
Copy link

Hello Team

We've been experiencing for over a year now. We truly appreciate your efforts in addressing this matter.

Do we have any updates on the progress made so far, or could you provide an estimated timeline for when this issue might be resolved? Understanding the complexities involved, any information you can share about the current status or future plans would be immensely helpful for our team.

The screenshot I provided depicts an error report from Sentry, highlighting the frequency of occurrences for this particular error.
twilio-device-state

@charliesantos
Copy link
Collaborator

Hi @vasanthnathan, the fix is already on master branch. See changelog https://github.com/twilio/twilio-voice.js/blob/master/CHANGELOG.md#2100-in-progress

It will get released in Jan. Thanks for bearing with us.

@charliesantos
Copy link
Collaborator

fixed in 2.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working jira added
Projects
None yet
Development

No branches or pull requests