Skip to content

Commit 90bc0ad

Browse files
Improve idle timer and connection state log messages
Add connection ID, error codes, and actionable context to connection lifecycle log messages. The idle timer expiry now explains what will happen next (disconnect + reconnect) and includes the error code 80003. A new LOG_MINOR message logs when the connection is resumed or reestablished after disconnection, providing a bookend to the idle expiry message. The connection state freshness check now explains consequences (new connection, channel reattach) and includes the connection state TTL and connection ID. Also replace "realtime" with "Ably" in user-facing log messages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c90f1c3 commit 90bc0ad

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/common/lib/transport/connectionmanager.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ class ConnectionManager extends EventEmitter {
644644
this.activeProtocol = new Protocol(transport);
645645
this.host = transport.params.host;
646646

647+
const prevConnId = this.connectionId;
647648
const connectionKey = connectionDetails.connectionKey;
648649
if (connectionKey && this.connectionKey != connectionKey) {
649650
this.setConnection(connectionId, connectionDetails, !!error);
@@ -673,6 +674,19 @@ class ConnectionManager extends EventEmitter {
673674
this.emit('update', new ConnectionStateChange(connectedState, connectedState, null, error));
674675
}
675676
} else {
677+
if (existingState.state === this.states.disconnected.state) {
678+
const resumed = prevConnId === connectionId;
679+
Logger.logAction(
680+
this.logger,
681+
Logger.LOG_MINOR,
682+
'ConnectionManager.activateTransport()',
683+
'Connection ' +
684+
(resumed ? 'resumed' : 'reestablished') +
685+
' after disconnection; connectionId: ' +
686+
connectionId +
687+
(prevConnId && !resumed ? ' (previously: ' + prevConnId + ')' : ''),
688+
);
689+
}
676690
this.notifyState({ state: 'connected', error: error });
677691
this.errorReason = this.realtime.connection.errorReason = error || null;
678692
}
@@ -876,7 +890,13 @@ class ConnectionManager extends EventEmitter {
876890
this.logger,
877891
Logger.LOG_MINOR,
878892
'ConnectionManager.checkConnectionStateFreshness()',
879-
'Last known activity from realtime was ' + sinceLast + 'ms ago; discarding connection state',
893+
'Last known activity from Ably was ' +
894+
sinceLast +
895+
'ms ago (exceeds freshness threshold of ' +
896+
(this.connectionStateTtl + (this.maxIdleInterval as number)) +
897+
'ms); discarding connection state. ' +
898+
'A new connection will be established and channels will reattach' +
899+
(this.connectionId ? '; connectionId: ' + this.connectionId : ''),
880900
);
881901
this.clearConnection();
882902
this.states.connecting.failState = 'suspended';

src/common/lib/transport/transport.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,14 @@ abstract class Transport extends EventEmitter {
290290
const sinceLast = Date.now() - this.lastActivity;
291291
const timeRemaining = this.maxIdleInterval - sinceLast;
292292
if (timeRemaining <= 0) {
293-
const msg = 'No activity seen from realtime in ' + sinceLast + 'ms; assuming connection has dropped';
293+
const connId = this.connectionManager.connectionId;
294+
const msg =
295+
'No activity seen from Ably in ' +
296+
sinceLast +
297+
'ms; assuming connection has dropped. ' +
298+
'Will disconnect and reconnect automatically (error code: 80003, status: 408' +
299+
(connId ? ', connectionId: ' + connId : '') +
300+
')';
294301
Logger.logAction(this.logger, Logger.LOG_ERROR, 'Transport.onIdleTimerExpire()', msg);
295302
this.disconnect(new ErrorInfo(msg, 80003, 408));
296303
} else {

0 commit comments

Comments
 (0)