Skip to content

Commit 548cb7a

Browse files
authored
Fix: multiple message processing overlap bug when SSL mode is 'disabled'. (#400)
1 parent 8d57261 commit 548cb7a

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 3.4.5
44

55
- `close(force: true)` to indicate intent to force-close pending queries and resources. [#396](https://github.com/isoos/postgresql-dart/pull/396) by [davidmartos96](https://github.com/davidmartos96)
6+
- Fix: multiple message processing overlap bug when SSL mode was `disabled`.
67

78
## 3.4.4
89

lib/src/v3/protocol.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ StreamTransformer<Uint8List, ServerMessage> _readMessages(
6969
}
7070
}
7171

72-
Future<void> handleChunk(Uint8List bytes) async {
72+
Future<void> handleChunk() async {
7373
try {
74-
await framer.addBytes(bytes);
74+
// await framer.addBytes(bytes);
7575
emitFinishedMessages();
7676
} catch (e, st) {
7777
listener.addErrorSync(e, st);
@@ -80,10 +80,12 @@ StreamTransformer<Uint8List, ServerMessage> _readMessages(
8080

8181
// Don't cancel this subscription on error! If the listener wants that,
8282
// they'll unsubscribe in time after we forward it synchronously.
83-
final rawSubscription =
84-
rawStream.listen(handleChunk, cancelOnError: false)
85-
..onError(listener.addErrorSync)
86-
..onDone(listener.closeSync);
83+
final rawSubscription = rawStream
84+
// TODO: figure out a better way to handle multiple callbacks to framer
85+
.asyncMap(framer.addBytes)
86+
.listen((_) => handleChunk(), cancelOnError: false)
87+
..onError(listener.addErrorSync)
88+
..onDone(listener.closeSync);
8789

8890
listener.onPause = () {
8991
paused = true;

test/event_after_closing_test.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,18 @@ void main() {
6969
_print('Inserted ${numBatches * batchSize} rows in ${sw.elapsed}');
7070
}
7171

72-
test('issue#398', () async {
73-
final conn = await server.newConnection();
72+
test('issue#398 ssl:disabled', () async {
73+
final conn = await server.newConnection(sslMode: SslMode.disable);
74+
await createTableAndPopulate(conn);
75+
76+
final rows = await conn.execute('SELECT * FROM large_table');
77+
_print('SELECTED ROWS ${rows.length}');
78+
79+
await conn.close();
80+
});
81+
82+
test('issue#398 ssl:require', () async {
83+
final conn = await server.newConnection(sslMode: SslMode.require);
7484
await createTableAndPopulate(conn);
7585

7686
final rows = await conn.execute('SELECT * FROM large_table');

0 commit comments

Comments
 (0)