Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw Exception io.netty.util.IllegalReferenceCountException: refCnt: 0 #673

Open
begone1992 opened this issue May 10, 2022 · 1 comment

Comments

@begone1992
Copy link

Expected behavior

I am trying to create mqtt message from code and then publish it.

Actual behavior

But in PublishListener event when I am trying get payload this exception io.netty.util.IllegalReferenceCountException: refCnt: 0 throws every time.

Steps to reproduce

Here is my code:
_mqttBroker = new Server();
final List<? extends InterceptHandler> userHandlers = Arrays.asList(new PublisherListener());
_mqttBroker.startServer(server_config, userHandlers);
String clientID = "a2bae31a-6c4f-4076-ae66-5aadf3668b0a";
MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, false, MqttQoS.AT_LEAST_ONCE, false, 0);
MqttPublishVariableHeader headerTopic = new MqttPublishVariableHeader(topic, 0);
ByteBuf anypayload = Unpooled.wrappedBuffer(data.getBytes());
MqttPublishMessage msg = new MqttPublishMessage(mqttFixedHeader, headerTopic, anypayload);
_mqttBroker.internalPublish(msg, clientID);
InterceptPublishMessage message = new InterceptPublishMessage(msg, clientID, clientID);
new PublisherListener().onPublish(message);

public void onPublish(InterceptPublishMessage message) {
System.out.println("moquette mqtt broker message intercepted, topic: " + message.getTopicName()
+ ", content: ");
System.out.println(message.getPayload());
byte[] bytes = new byte[message.getPayload().readableBytes()];
message.getPayload().duplicate().readBytes(bytes);
System.out.println(new String(bytes));
SensorContext.MessageRecieved(message);
}

Moquette MQTT version

moquette-broker-0.15

JVM version (e.g. java -version)

1.8.0_312

OS version (e.g. uname -a)

Ubuntu 20

@hylkevds
Copy link
Collaborator

The code you posted is very incomplete. Can you make a self-contained test that shows the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants