Repository navigation
Closed
Description
Search before asking
- I searched in the issues and found nothing similar.
Version
- Pulsar 3.1.0
- Client: eea59bb
Additional broker configs:
brokerDeduplicationEnabled=true
maxMessageSize=1024000Minimal reproduce step
To simulate the send error is returned, we need to run the following code on a Pulsar release that does not include apache/pulsar#20948
#include <pulsar/Client.h>
#include <chrono>
#include <iostream>
#include <thread>
using namespace pulsar;
int main() {
Client client("pulsar://127.0.0.1:6650");
Producer producer;
ProducerConfiguration conf;
conf.setBatchingEnabled(false);
conf.setChunkingEnabled(true);
client.createProducer("persistent://public/default/my-topic", conf, producer);
producer.sendAsync(MessageBuilder().setContent(std::string(1024000 * 5, 'a')).build(),
[](Result result, const MessageId& msgId) {
std::cout << "XYZ send " << result << " " << msgId << std::endl;
});
std::this_thread::sleep_for(std::chrono::seconds(1));
client.close();
}What did you expect to see?
The application exits normally.
What did you see instead?
2023-10-08 11:41:38.699 WARN [0x16f05b000] ClientConnection:1529 | [127.0.0.1:55532 -> 127.0.0.1:6650] Received send error from server: Cannot determine whether the message is a duplicate at this time
2023-10-08 11:41:38.699 INFO [0x16f05b000] ClientConnection:1340 | [127.0.0.1:55532 -> 127.0.0.1:6650] Connection disconnected
2023-10-08 11:41:38.699 INFO [0x16f05b000] HandlerBase:141 | [persistent://public/default/test-send-chunks, standalone-12-4] Schedule reconnection in 0.1 s
2023-10-08 11:41:38.699 INFO [0x16f05b000] ConnectionPool:122 | Remove connection for pulsar://127.0.0.1:6650
2023-10-08 11:41:38.699 INFO [0x16f05b000] ClientConnection:268 | [127.0.0.1:55532 -> 127.0.0.1:6650] Destroyed connection to pulsar://127.0.0.1:6650
You can also see the failure reproduced in this workflow:
[----------] 1 test from ChunkDedupTest
[ RUN ] ChunkDedupTest.testSendChunks
2023-10-08 03:32:50.574 INFO [139665533579648] ClientConnection:188 | [<none> -> pulsar://localhost:6650] Create ClientConnection, timeout=10000
2023-10-08 03:32:50.574 INFO [139665533579648] ConnectionPool:107 | Created connection for pulsar://localhost:6650
2023-10-08 03:32:50.578 INFO [139665518995008] ClientConnection:398 | [[::1]:43874 -> [::1]:6650] Connected to broker
2023-10-08 03:32:50.655 INFO [139665518995008] HandlerBase:81 | [persistent://public/default/test-send-chunks, ] Getting connection from pool
2023-10-08 03:32:51.124 INFO [1396[655](https://github.com/BewareMyPower/pulsar-client-cpp/actions/runs/6445210808/job/17499021562?pr=22#step:8:656)18995008] ProducerImpl:199 | [persistent://public/default/test-send-chunks, ] Created producer on broker [[::1]:43874 -> [::1]:6650]
2023-10-08 03:32:51.293 WARN [139665518995008] ClientConnection:1528 | [[::1]:43874 -> [::1]:6650] Received send error from server: Cannot determine whether the message is a duplicate at this time
2023-10-08 03:32:51.294 INFO [139665518995008] ClientConnection:1340 | [[::1]:43874 -> [::1]:6650] Connection disconnected
2023-10-08 03:32:51.294 INFO [139665518995008] ConnectionPool:122 | Remove connection for pulsar://localhost:6650
2023-10-08 03:32:51.294 INFO [1396[655](https://github.com/BewareMyPower/pulsar-client-cpp/actions/runs/6445210808/job/17499021562?pr=22#step:8:656)18995008] HandlerBase:141 | [persistent://public/default/test-send-chunks, standalone-0-0] Schedule reconnection in 0.1 s
2023-10-08 03:32:51.295 INFO [139665518995008] ClientConnection:268 | [[::1]:43874 -> [::1]:6650] Destroyed connection to pulsar://localhost:6650
./run-unit-tests.sh: line 51: 6925 Segmentation fault (core dumped) $CMAKE_BUILD_DIRECTORY/tests/ChunkDedupTest --gtest_repeat=10
Error: Process completed with exit code 139.
Anything else?
The root cause might be #317. I tried reverting that commit in my local env and it never crashed.
Here is also a similar crash report: #324
Are you willing to submit a PR?
- I'm willing to submit a PR!
Metadata
Metadata
Assignees
Labels
No labels
Activity
BewareMyPower commentedon Oct 8, 2023
Here are the LLDB debug result:
The underlying implementation of
boost::asio::async_write(socket, ...)is:write_opobject that wraps the buffer tosocket. See the following code fromboost/asio/impl/write.hppof Boost 1.82.socket.async_write_somein a loop until the whole buffer is sent successfully. See the frame 9 in the stacks above. (So It cannot be reproduced with small messages becauseasync_write_somecould once send all bytes.)As we can see, the application crashed at
async_write_someafter theClientConnectionobject is destructed (see theDestroyed connection to pulsar://127.0.0.1:6650log before the crash) After closing the socket, thewrite_opwill break the loop withoperation_abortedand then trigger a callback in the event loop.In
ClientConnection::close, theClientConnectionobject will be removed from the pool viapool_.remove. Since only theConnectionPoolowns theClientConnection, theClientConnectionobject, as well as thesocket_field, will be destroyed after it's removed from the pool.However, the
write_opobject is registered with the socket (stream_here) object, the next time when Asio event loop executes the callback, a destroyed socket address will be accessed. Before #317, theClientConnectionis owned by the callback rather than the pool. TheClientConnectionobject will be passed into the next callback. Only after the last callback that ownsClientConnectionis completed will it be destroyed.[-][Bug] Segmentation fault when sending messages after receiving send error [/-][+][Bug] Segmentation fault when sending messages after receiving an error [/+]Fix segmentation fault when sending messages after receiving an error
Fix segmentation fault when sending messages after receiving an error (…
Fix segmentation fault when sending messages after receiving an error (…