Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmartos96 committed Jun 20, 2024
1 parent 3c053ce commit 173f372
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/electricsql/lib/src/client/model/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ElectricClientImpl extends ElectricNamespace

@override
void disconnect() {
print("${DateTime.now()} PROCESS DISCONNECT FROM CLIENT");
satellite.disconnect(null);
}

Expand Down
5 changes: 5 additions & 0 deletions packages/electricsql/lib/src/satellite/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class SatelliteClient implements Client {
}

if (isConnected()) {
print("${DateTime.now()} DISCONNECT BEFORE CONNECTING");
disconnect();
}

Expand All @@ -253,6 +254,7 @@ class SatelliteClient implements Client {
this.socket = socket;

void onceError(Object error, StackTrace st) {
print("${DateTime.now()} DISCONNECT BECAUSE ERROR $error\n\t$st");
disconnect();
completer.completeError(error, st);
}
Expand All @@ -269,6 +271,7 @@ class SatelliteClient implements Client {
socket.onMessage(socketHandler!);
socket.onError((error, st) {
if (_emitter.listenerCount('error') == 0) {
print("${DateTime.now()} DISCONNECT ON ERROR BECAUSE LISTENER COUNT 0");
disconnect();
logger.error(
'socket error but no listener is attached: $error',
Expand All @@ -277,6 +280,7 @@ class SatelliteClient implements Client {
_emitter.enqueueEmitError(error, st);
});
socket.onClose((reason) {
print("${DateTime.now()} DISCONNECT ON CLOSE BECAUSE REASON ${reason.code}");
disconnect();
if (_emitter.listenerCount('error') == 0) {
logger.error('socket closed but no listener is attached');
Expand Down Expand Up @@ -327,6 +331,7 @@ class SatelliteClient implements Client {

@override
void shutdown() {
print("${DateTime.now()} SATELLITE CLIENT SHUTDOWN");
disconnect();
_emitter.removeAllListeners();
_isDown = true;
Expand Down
7 changes: 7 additions & 0 deletions packages/electricsql/lib/src/satellite/process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ This means there is a notifier subscription leak.`''');
// interact with a closed database connection
await _waitForActiveSnapshots();

print("${DateTime.now()} PROCESS DISCONNECT ON STOP");
disconnect(null);

if (shutdown == true) {
Expand Down Expand Up @@ -627,6 +628,7 @@ INSERT $orIgnore INTO $qualifiedTableName (${columnNames.join(', ')}) VALUES '''
bool keepSubscribedShapes = false,
}) async {
logger.warning('resetting client state');
print("${DateTime.now()} PROCESS DISCONNECT WHEN RESETTING CLIENT STATE");
disconnect(null);
final subscriptionIds = subscriptions.getFulfilledSubscriptions();

Expand Down Expand Up @@ -744,6 +746,7 @@ INSERT $orIgnore INTO $qualifiedTableName (${columnNames.join(', ')}) VALUES '''
Future<void> _handleOrThrowClientError(SatelliteException error) async {
if (error.code == SatelliteErrorCode.authExpired) {
logger.warning('Connection closed by Electric because the JWT expired.');
print("${DateTime.now()} PROCESS DISCONNECT BECAUSE AUTH EXPIRED");
return disconnect(
SatelliteException(
error.code,
Expand All @@ -752,6 +755,7 @@ INSERT $orIgnore INTO $qualifiedTableName (${columnNames.join(', ')}) VALUES '''
);
}

print("${DateTime.now()} PROCESS DISCONNECT WHEN HANDLING ERROR");
disconnect(error);

if (isThrowable(error)) {
Expand Down Expand Up @@ -861,6 +865,7 @@ INSERT $orIgnore INTO $qualifiedTableName (${columnNames.join(', ')}) VALUES '''
stackTrace = StackTrace.current;
}

print("${DateTime.now()} PROCESS DISCONNECT ON CONNECT WITH BACKOFF");
disconnect(error is SatelliteException ? error : null);
initializing?.completeError(error, stackTrace);
}
Expand Down Expand Up @@ -929,6 +934,7 @@ INSERT $orIgnore INTO $qualifiedTableName (${columnNames.join(', ')}) VALUES '''

@override
void disconnect(SatelliteException? error) {
print("${DateTime.now()} DISCONNECT BECAUSE PROCESS DISCONNECT: ${error?.code} ${error?.message}");
client.disconnect();
_notifyConnectivityState(ConnectivityStatus.disconnected, error);
}
Expand All @@ -940,6 +946,7 @@ INSERT $orIgnore INTO $qualifiedTableName (${columnNames.join(', ')}) VALUES '''
SatelliteErrorCode.connectionCancelledByDisconnect,
"Connection cancelled by 'disconnect'",
);
print("${DateTime.now()} PROCESS DISCONNECT FROM CLIENTDISCONNECT");
disconnect(error);
cancelConnectionWaiter(error);
}
Expand Down

0 comments on commit 173f372

Please sign in to comment.