Skip to content

Commit 3352978

Browse files
authored
Do not allow exceptions escape when closing broken connection (isoos#384)
1 parent 6881361 commit 3352978

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/src/v3/connection.dart

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -581,23 +581,27 @@ class PgConnectionImplementation extends _PgSessionBase implements Connection {
581581
_socketIsBroken = _socketIsBroken || socketIsBroken;
582582
if (!_isClosing) {
583583
_isClosing = true;
584-
585-
if (interruptRunning) {
586-
_pending?.handleConnectionClosed(cause);
587-
if (!_socketIsBroken) {
588-
_channel.sink.add(const TerminateMessage());
589-
}
590-
} else {
591-
// Wait for the previous operation to complete by using the lock
592-
await _operationLock.withResource(() {
584+
try {
585+
if (interruptRunning) {
586+
_pending?.handleConnectionClosed(cause);
593587
if (!_socketIsBroken) {
594588
_channel.sink.add(const TerminateMessage());
595589
}
596-
});
597-
}
590+
} else {
591+
// Wait for the previous operation to complete by using the lock
592+
await _operationLock.withResource(() {
593+
if (!_socketIsBroken) {
594+
_channel.sink.add(const TerminateMessage());
595+
}
596+
});
597+
}
598598

599-
await Future.wait([_channel.sink.close(), _serverMessages.cancel()]);
600-
_closeSession();
599+
await Future.wait([_channel.sink.close(), _serverMessages.cancel()]);
600+
_closeSession();
601+
} catch (err) {
602+
// error in _close(), silencing since the connection is no longer
603+
// usable anyway
604+
}
601605
}
602606
}
603607

0 commit comments

Comments
 (0)