You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could it be reproduce it via a simple C++ application? What's the C++ client version you're using? The pre-built binaries or you built from source? It's recommended to use vcpkg to install now.
Hi @BewareMyPower, I think there might be a race condition in the client/consumer([email protected]).
In our case, we close the consumer immediately after performing a seek operation. It seems there's a timing issue: when we try to create a new consumer right after closing the previous one, we occasionally hit a "consumer busy" error.
#include<iostream>
#include<thread>
#include<pulsar/Client.h>usingnamespacestd;usingnamespacepulsar;intmain() {
Client client("pulsar://localhost:6650");
constauto topic = "persistent://public/default/my-topic-1";
// Create producer
Producer producer;
constauto producerRes = client.createProducer(topic, producer);
if (producerRes != ResultOk) {
cout << "Failed to create producer: " << producerRes << endl;
return1;
}
// Create consumer
Consumer consumer;
ConsumerConfiguration consConfig;
consConfig.setMessageListener([](Consumer &consumer, const Message &msg) {
cout << msg.getMessageId() << endl;
});
std::string subName = "sub";
constauto subscribeRes = client.subscribe(topic, subName, consConfig, consumer);
if (subscribeRes != ResultOk) {
cout << "Failed to subscribe: " << subscribeRes << endl;
return1;
}
constauto seekTS = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).
count();
std::string msgContent = "msg-content";
const Message msg = MessageBuilder().setContent("content").setProperty("x", "1").build();
producer.send(msg);
std::this_thread::sleep_for(std::chrono::seconds(3));
constauto consumer1SeekRes = consumer.seek(seekTS);
cout << "Consumer1 seek result: " << consumer1SeekRes << endl;
if (consumer1SeekRes != ResultOk) {
return1;
}
// When the client performs the seek operation, the broker disconnects the consumer, and then the consumer re-subscribes in the background.// If we close the consumer immediately after the seek operation, there may be a race condition.// Uses sleep_for to reduce the race condition.// cout << "sleep_for 5s" << endl; // std::this_thread::sleep_for(std::chrono::seconds(5));constauto closeRes = consumer.close();
cout << "Consumer1 close result: " << closeRes << endl;
if (closeRes != ResultOk) {
return1;
}
cout << "Starting consumer2" << endl;
Consumer consumer2;
constauto consumer2Res = client.subscribe(topic, subName, consConfig, consumer2);
cout << "Consumer2 subscribe result: " << consumer2Res << endl; // ConsumerBusyif (consumer2Res != ResultOk) {
return1;
}
constauto consumer2SeekRes = consumer2.seek(seekTS);
cout << "Consumer2 seek result: " << consumer2SeekRes << endl;
if (consumer2SeekRes != ResultOk) {
return1;
}
consumer2.close();
client.close();
return0;
}
Ah, that's right, it can be reproduced by 3.7.2 client on macOS. But this issue should have been fixed in master branch. Not sure which PR fixes it for now.
Activity
BewareMyPower commentedon Apr 27, 2025
It seems that you're using Python clients. What's the client version? Could it be reproduced with the latest Python client (3.6.1)?
haolujun commentedon Apr 27, 2025
oh, I don't use python client. I use cpp client in pybind. So, you can see somthing with python in stack. The python version is 3.7.13.
BewareMyPower commentedon Apr 27, 2025
Could it be reproduce it via a simple C++ application? What's the C++ client version you're using? The pre-built binaries or you built from source? It's recommended to use vcpkg to install now.
nodece commentedon Oct 21, 2025
Hi @BewareMyPower, I think there might be a race condition in the client/consumer([email protected]).
In our case, we close the consumer immediately after performing a seek operation. It seems there's a timing issue: when we try to create a new consumer right after closing the previous one, we occasionally hit a "consumer busy" error.
BewareMyPower commentedon Oct 21, 2025
I cannot reproduce this issue with the code above against a standalone.
@nodece If you can reproduce, could you share the full logs?
nodece commentedon Oct 21, 2025
@BewareMyPower
Run pulsar with standalone:
vcpkg.json:
{ "name": "client-cpp-test", "version-string": "0.1.0", "builtin-baseline": "38d1652f152d36481f2f4e8a85c0f1e14f3769f7", "dependencies": [ { "name": "pulsar-client-cpp", "version>=": "3.7.0" } ], "overrides": [ { "name": "zlib", "version": "1.3.1" } ] }Broker log:
Client log:
BewareMyPower commentedon Oct 24, 2025
Ah, that's right, it can be reproduced by 3.7.2 client on macOS. But this issue should have been fixed in master branch. Not sure which PR fixes it for now.
BewareMyPower commentedon Oct 24, 2025
Interesting, it can be reproduce on master branch as well, let me take a look