saltyrtc / saltyrtc-client-js

SaltyRTC JavaScript implementation.
MIT License
29 stars 6 forks source link

Race conditions when reconnecting #108

Open lgrahl opened 6 years ago

lgrahl commented 6 years ago

A WebSocket close is not immediate. We should return a Promise, wait for the close event and then resolve. However, the main problem is that we allow to .connect immediately after a .disconnect which results in racy behaviour as both WebSocket connections are bound to the same event handlers.

This would be a major change and requires significant refactoring. For now, applications should always either:

  1. Wait for the connection-closed event, or
  2. Unbind all events after a .disconnect, throw the SaltyRTC instance away and create a new one. Even if you do this, be prepared to see log messages from previous connections (I'm working on removing this).