Skip to content

Commit

Permalink
[C++] Fix segmentation fault when creating socket failed (#14834)
Browse files Browse the repository at this point in the history
### Motivation

#14823 fixes the flaky
`testConnectTimeout` but it's also a regression of
#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 54c368e)
  • Loading branch information
BewareMyPower committed Mar 24, 2022
1 parent 8eefaff commit b5b8cb0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pulsar-client-cpp/lib/ClientConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,9 @@ void ClientConnection::close(Result result) {
consumerStatsRequestTimer_.reset();
}

connectTimeoutTask_->stop();
if (connectTimeoutTask_) {
connectTimeoutTask_->stop();
}

lock.unlock();
LOG_INFO(cnxString_ << "Connection closed");
Expand Down

0 comments on commit b5b8cb0

Please sign in to comment.