-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix segmentation fault when sending messages after receiving an error (…
…#326) Fixes #325 ### Motivation #317 introduces a bug that might cause segmentation fault when sending messages after receiving an error, see #325 (comment) for the detailed explanation. ### Modifications When calling `asyncWrite`, capture the `shared_ptr` instead of the `weak_ptr` to extend the lifetime of the `socket_` or `tlsSocket_` field in `ClientConnection`. Since the lifetime is extended, in some callbacks, check `isClosed()` before other logic. Add a `ChunkDedupTest` to reproduce this issue based on Pulsar 3.1.0. Run the test for 10 times to ensure it won't crash after this patch.
- Loading branch information
1 parent
eea59bb
commit 5c77648
Showing
5 changed files
with
148 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
#include <gtest/gtest.h> | ||
#include <pulsar/Client.h> | ||
|
||
#include "lib/Latch.h" | ||
#include "lib/LogUtils.h" | ||
|
||
DECLARE_LOG_OBJECT() | ||
|
||
using namespace pulsar; | ||
|
||
// Before https://github.com/apache/pulsar/pull/20948, when message deduplication is enabled, sending chunks | ||
// to the broker will receive send error response. | ||
TEST(ChunkDedupTest, testSendChunks) { | ||
Client client{"pulsar://localhost:6650"}; | ||
ProducerConfiguration conf; | ||
conf.setBatchingEnabled(false); | ||
conf.setChunkingEnabled(true); | ||
Producer producer; | ||
ASSERT_EQ(ResultOk, client.createProducer("test-send-chunks", conf, producer)); | ||
|
||
Latch latch{1}; | ||
std::string value(1024000 /* max message size */ * 100, 'a'); | ||
producer.sendAsync(MessageBuilder().setContent(value).build(), | ||
[&latch](Result result, const MessageId& msgId) { | ||
LOG_INFO("Send to " << msgId << ": " << result); | ||
latch.countdown(); | ||
}); | ||
ASSERT_TRUE(latch.wait(std::chrono::seconds(10))); | ||
client.close(); | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
version: '3' | ||
networks: | ||
pulsar: | ||
driver: bridge | ||
services: | ||
standalone: | ||
# Don't change the version here to ensure https://github.com/apache/pulsar/pull/20948 is not included | ||
image: apachepulsar/pulsar:3.1.0 | ||
container_name: standalone | ||
hostname: local | ||
restart: "no" | ||
networks: | ||
- pulsar | ||
environment: | ||
- metadataStoreUrl=zk:localhost:2181 | ||
- clusterName=standalone | ||
- advertisedAddress=localhost | ||
- advertisedListeners=external:pulsar://localhost:6650 | ||
- PULSAR_MEM=-Xms512m -Xmx512m -XX:MaxDirectMemorySize=256m | ||
- PULSAR_PREFIX_maxMessageSize=1024000 | ||
- PULSAR_PREFIX_brokerDeduplicationEnabled=true | ||
ports: | ||
- "6650:6650" | ||
- "8080:8080" | ||
command: bash -c "bin/apply-config-from-env.py conf/standalone.conf && exec bin/pulsar standalone -nss -nfw" | ||
|