diff --git a/lib/src/v3/connection.dart b/lib/src/v3/connection.dart index 33d599b..8bc1126 100644 --- a/lib/src/v3/connection.dart +++ b/lib/src/v3/connection.dart @@ -229,15 +229,16 @@ class PgConnectionImplementation extends _PgSessionBase implements Connection { ); if (_debugLog) { + final hash = channel.hashCode; channel = channel.transform(StreamChannelTransformer( StreamTransformer.fromHandlers( handleData: (msg, sink) { - print('[in] $msg'); + print('[$hash in] $msg'); sink.add(msg); }, ), async.StreamSinkTransformer.fromHandlers(handleData: (msg, sink) { - print('[out] $msg'); + print('[$hash out] $msg'); sink.add(msg); }), )); @@ -493,12 +494,22 @@ class PgConnectionImplementation extends _PgSessionBase implements Connection { timeout ??= _settings.queryTimeout; if (timeout.isNegative) return; if (timeout == _lastStatementTimeout) return; - await _doExecuteSimpleQuery( - InternalQueryDescription.direct( - 'SET statement_timeout TO ${timeout.inMilliseconds};'), - true, - ); - _lastStatementTimeout = timeout; + + try { + await _doExecuteSimpleQuery( + InternalQueryDescription.direct( + 'SET statement_timeout TO ${timeout.inMilliseconds};'), + true, + ); + _lastStatementTimeout = timeout; + } on ServerException catch (e) { + // we ignore error messages if they happen inside a failed transaction block + if (e.code == '25P02') { + return; + } + // rethrow otherwise + rethrow; + } } @override diff --git a/test/timeout_test.dart b/test/timeout_test.dart index ae543dd..8cc435b 100644 --- a/test/timeout_test.dart +++ b/test/timeout_test.dart @@ -102,13 +102,17 @@ void main() { await c2.execute('BEGIN'); await expectLater( - () => c2.execute('SELECT * FROM t WHERE id=1 FOR UPDATE;', - timeout: Duration(seconds: 1)), - throwsA(isA())); + () => c2.execute( + 'SELECT * FROM t WHERE id=1 FOR UPDATE;', + timeout: Duration(seconds: 1), + ), + throwsA(isA()), + ); await c1.execute('COMMIT'); - // This line fails: - // await c2.execute('ROLLBACK'); + await c2.execute('COMMIT'); + + await c2.execute('SELECT * FROM t;'); }); }); }