You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by xy...@apache.org on 2022/03/24 09:50:52 UTC
[pulsar] 03/03: [C++] Fix segmentation fault when creating socket failed (#14834)
This is an automated email from the ASF dual-hosted git repository.
xyz pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit a62c371148160027984b4312734f02d4e990b227
Author: Yunze Xu <xy...@163.com>
AuthorDate: Thu Mar 24 15:29:16 2022 +0800
[C++] Fix segmentation fault when creating socket failed (#14834)
### Motivation
https://github.com/apache/pulsar/pull/14823 fixes the flaky
`testConnectTimeout` but it's also a regression of
https://github.com/apache/pulsar/pull/14587. Because when the fd limit
is reached, the `connectionTimeoutTask_` won't be initialized with a
non-null value. Calling `stop` method on it directly will cause
segmentation fault.
See
https://github.com/apache/pulsar/blob/0fe921f32cefe7648ca428cd9861f9163c69767d/pulsar-client-cpp/lib/ClientConnection.cc#L178-L185
### Modifications
Add the null check for `connectionTimeoutTask_` in `ClientConnection::close`.
(cherry picked from commit 54c368ed3744a40240205c17bdcac5cef48130e4)
---
pulsar-client-cpp/lib/ClientConnection.cc | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/pulsar-client-cpp/lib/ClientConnection.cc b/pulsar-client-cpp/lib/ClientConnection.cc
index efc3cd5..6071d0e 100644
--- a/pulsar-client-cpp/lib/ClientConnection.cc
+++ b/pulsar-client-cpp/lib/ClientConnection.cc
@@ -1549,7 +1549,9 @@ void ClientConnection::close(Result result) {
consumerStatsRequestTimer_.reset();
}
- connectTimeoutTask_->stop();
+ if (connectTimeoutTask_) {
+ connectTimeoutTask_->stop();
+ }
lock.unlock();
LOG_INFO(cnxString_ << "Connection closed");