From 0bdc0d6a8e6e88eb159fb22f79082013c99480d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20So=C3=B3s?= Date: Wed, 13 Dec 2023 17:24:33 +0100 Subject: [PATCH] Fix SSL connection handler. (#271) --- CHANGELOG.md | 4 ++++ lib/src/v3/connection.dart | 19 ++++++++++++++++--- pubspec.yaml | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8bcb36..ebde187 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.0.4 + +- Fix: SSL connection problem handler. + ## 3.0.3 - Using const for ConnectionSettings, SessionSettings and PoolSettings classes. ([#267](https://github.com/isoos/postgresql-dart/pull/267) by [Gerrel](https://github.com/Gerrel)) diff --git a/lib/src/v3/connection.dart b/lib/src/v3/connection.dart index 4ef2b5a..384c4b4 100644 --- a/lib/src/v3/connection.dart +++ b/lib/src/v3/connection.dart @@ -243,6 +243,9 @@ class PgConnectionImplementation extends _PgSessionBase implements Connection { // ignore: cancel_subscriptions final subscription = socket.listen( (data) { + if (sslCompleter.isCompleted) { + return; + } if (data.length != 1) { sslCompleter.completeError(PgException( 'Could not initialize SSL connection, received unknown byte stream.')); @@ -251,9 +254,19 @@ class PgConnectionImplementation extends _PgSessionBase implements Connection { sslCompleter.complete(data.first); }, - onDone: () => sslCompleter.completeError(PgException( - 'Could not initialize SSL connection, connection closed during handshake.')), - onError: sslCompleter.completeError, + onDone: () { + if (sslCompleter.isCompleted) { + return; + } + sslCompleter.completeError(PgException( + 'Could not initialize SSL connection, connection closed during handshake.')); + }, + onError: (e) { + if (sslCompleter.isCompleted) { + return; + } + sslCompleter.completeError(e); + }, ); Stream adaptedStream; diff --git a/pubspec.yaml b/pubspec.yaml index acdf35b..dcd536c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: postgres description: PostgreSQL database driver. Supports statement reuse and binary protocol and connection pooling. -version: 3.0.3 +version: 3.0.4 homepage: https://github.com/isoos/postgresql-dart topics: - sql