docs icon indicating copy to clipboard operation
docs copied to clipboard

Prevent simultaneous authentication requests

Open mattheworiordan opened this issue 6 years ago • 0 comments

See https://github.com/ably/ably-java/issues/459

In the current specification, it is possible that multiple concurrent authentication callbacks can be invoked when a client library has not yet been authenticated. For example, the following pseudo code and side effects are permitted currently by the spec:

let authCallback = fn {
  console.log('Getting a new token: ', calculateTimeElapsed())
  wait(1000);
  return tokenFromSomeWhere;
}
let ably = new Ably.Rest({ authCallback: authCallback })
async.wait(
  ably.channel('foo').publish(),
  ably.channel('foo').publish(),
  ably.channel('foo').publish(),
  ably.channel('foo').publish()
)
console.log('done: ', calculateTimeElapsed())

# when run would output the following

-> Getting a new token: 1
-> Getting a new token: 2
-> Getting a new token: 4
-> Getting a new token: 5
-> done: 1005

This of course is a) not really an issue as getting new tokens is valid, b) unlikely to happen given most people perform sync operations with Rest, and wait for a connection to become connected with Realtime before performing other operations, however it would be nice to perhaps consider optimising this edge case in future if we can find a simple solution.

The complexity in resolving this is:

  • We'd need a mutex within the lib
  • If a single callback does not respond, it will block all other operations
  • If subsequent callbacks have different auth options, should they be blocked by the mutex or run in parallel

This is a low priority issue for now given the severity is negligible.

┆Issue is synchronized with this Jira Task by Unito

mattheworiordan avatar Feb 18 '19 23:02 mattheworiordan