stencila/executa

WebSocketClient: High browser CPU usage when remote executor exits

Opened this issue · 0 comments

The WebSocketClient contains logic to attempt re-connection if the connection is closed. This includes the use of retry from the p-retry package - which is supposed to have exponential backoff. However, I've noticed during testing that sometimes, when the remote executor is ended, that CPU usage goes up, probably due to something here:

socket.onclose = (event: CloseEvent) => {
// Try to reconnect if not explicitly closed or if
// authentication failed
if (this.stopped === true) return
const { code, reason } = event
if (code === 4001) {
if (logging) log.error(`Failed to authenticate with server: ${reason}`)
return
}
if (retries > 0) {
if (logging) log.info(`Connection closed, trying to reconnect`)
retry(() => this.start(), {
retries,
randomize: true
}).catch(error => log.error(error))
}
}