Project

General

Profile

Actions

Idea #7658

closed

[SDK] Python websockets reconnect on unexpected close

Added by Peter Amstutz over 8 years ago. Updated about 8 years ago.

Status:
Resolved
Priority:
Normal
Assigned To:
Radhika Chippada
Category:
SDKs
Target version:
Story points:
2.0

Description

In order to start having long-running tasks that rely on websockets events to trigger state changes, we need to ensure that the Python websockets client will automatically reconnect when there is an unexpected disconnect.

Acceptance criteria

  • The public interface of EventClient does not change.
  • Clients that use the public interface of EventClient are automatically get reconnected to websockets. In other words, the on_event callback is called with an uninterrupted stream of events, even if the underlying client has to connect to the websockets server multiple times to provide it.
  • Existing tests should continue to pass without modifying the public methods called and the results they return.
  • Add a test that forcibly disconnects the client and asserts that it automatically reconnects and passes in the correct last_log_id.

Suggested implementation

  1. The current EventClient class becomes an internal class (_EventClient)
  2. Add a on_closed() callback to _EventClient.
  3. Create a new EventClient class that inherits from object.
  4. EventClient takes on_event in the constructor and has the following public API: subscribe(), unsubscribe(), close()
  5. EventClient creates an instance of _EventClient and sets callbacks on_event() and on_closed() to itself
  6. When subscribe() and unsubscribe() are called EventClient, record in an array and then forward to _EventClient
  7. When events are called from _EventClient, record the sequence number "id" in last_log_id and forward them to the real on_event() handler.
  8. If close() is called by user, set a flag
  9. If on_closed() event is called on EventClient, but close flag is false, disconnect from old _EventClient object, create a new _EventClient object, and replay the subscriptions with last_log_id set

Subtasks 1 (0 open1 closed)

Task #8853: Review branch: 7658-websockets-reconnect-on-closeResolvedPeter Amstutz04/04/2016Actions

Related issues

Related to Arvados - Bug #9135: [SDKs] `arv ws -j` exits immediately with an errorResolvedBrett Smith05/06/2016Actions
Actions

Also available in: Atom PDF