Repository navigation
[C++] Fix segmentation fault when creating socket failed - #14834
Merged
BewareMyPower merged 1 commit intoMar 24, 2022
Merged
Conversation
### Motivation apache#14823 fixes the flaky `testConnectTimeout` but it's also a regression of apache#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`.
BewareMyPower
marked this pull request as draft
March 24, 2022 03:32
BewareMyPower
marked this pull request as ready for review
March 24, 2022 03:58
Contributor
Author
|
It looks hard to add a test. I tried to set the resource limit in tests but cannot restore the original value. #ifndef _MSC_VER
TEST(ClientTest, testTooManyFiles) {
struct rlimit originalLimit;
getrlimit(RLIMIT_NOFILE, &originalLimit);
struct rlimit currentLimit;
currentLimit.rlim_cur = 1;
currentLimit.rlim_max = 1;
setrlimit(RLIMIT_NOFILE, ¤tLimit);
/* Tests here ... */
setrlimit(RLIMIT_NOFILE, &originalLimit); // it failed with Operation not permitted
}
#endif |
michaeljmarshall
approved these changes
Mar 24, 2022
michaeljmarshall
left a comment
Member
There was a problem hiding this comment.
Thanks for your helpful explanation @BewareMyPower! LGTM
Demogorgon314
approved these changes
Mar 24, 2022
BewareMyPower
added a commit
that referenced
this pull request
Mar 24, 2022
### 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)
BewareMyPower
added a commit
that referenced
this pull request
Mar 24, 2022
### 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)
BewareMyPower
added a commit
that referenced
this pull request
Mar 24, 2022
### 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)
Nicklee007
pushed a commit
to Nicklee007/pulsar
that referenced
this pull request
Apr 20, 2022
### Motivation apache#14823 fixes the flaky `testConnectTimeout` but it's also a regression of apache#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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
#14823 fixes the flaky
testConnectTimeoutbut it's also a regression of#14587. Because when the fd limit
is reached, the
connectionTimeoutTask_won't be initialized with anon-null value. Calling
stopmethod on it directly will causesegmentation fault.
See
pulsar/pulsar-client-cpp/lib/ClientConnection.cc
Lines 178 to 185 in 0fe921f
Modifications
Add the null check for
connectionTimeoutTask_inClientConnection::close.