From 6b9ff43c848ea32138a4e1eceb5bbf7e20a59e16 Mon Sep 17 00:00:00 2001 From: Jianmin Zhao Date: Tue, 29 Oct 2024 11:36:31 -0700 Subject: [PATCH] CBL-6378: Crash when calling onWebSocketGotTLSCertificate callback after the connection is closed Have to synchronize _closed with onWebSocketGotTLSCertificate. --- Networking/BLIP/BLIPConnection.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Networking/BLIP/BLIPConnection.cc b/Networking/BLIP/BLIPConnection.cc index 61ccbd2af..b27b26af2 100644 --- a/Networking/BLIP/BLIPConnection.cc +++ b/Networking/BLIP/BLIPConnection.cc @@ -178,7 +178,9 @@ namespace litecore::blip { enqueue(FUNCTION_TO_QUEUE(BLIPIO::_gotHTTPResponse), status, headers); } - void onWebSocketGotTLSCertificate(slice certData) override { _connection->gotTLSCertificate(certData); } + virtual void onWebSocketGotTLSCertificate(slice certData) override { + enqueue(FUNCTION_TO_QUEUE(BLIPIO::_gotTLSCertificate), alloc_slice{certData}); + } // websocket::Delegate interface: void onWebSocketConnect() override { @@ -210,6 +212,11 @@ namespace litecore::blip { if ( _connection ) _connection->gotHTTPResponse(status, headers); } + void _gotTLSCertificate(alloc_slice certData) { + // _connection is reset to nullptr in _closed. + if ( _connection ) _connection->gotTLSCertificate(certData); + } + void _onWebSocketConnect() { // _connection is reset to nullptr in _closed. if ( _connection ) {