MQTT MessageHandler never called after a SIGTERM event #827
-
Hi, We're running an app that implements a Graceful shutdown. After receiving a SIGTERM event (from Kubernetes), it will allow the inflight HTTP requests to finish. Each request expects to receive an MQTT message to succeed. We have noticed that the public class MqttClientConnection extends CrtResource {
private class MessageHandler {
Consumer<MqttMessage> callback;
private MessageHandler(Consumer<MqttMessage> callback) {
this.callback = callback;
}
/* called from native when a message is delivered */
void deliver(String topic, byte[] payload, boolean dup, int qos, boolean retain) {
QualityOfService qosEnum = QualityOfService.getEnumValueFromInteger(qos);
callback.accept(new MqttMessage(topic, payload, qosEnum, retain, dup));
}
} Is it an expected behaviour? And if so, can we prevent it from happening? Thanks for your help 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Once the CRT's shutdown hook is executed by the JVM (presumably in response to the signal), no further callbacks are made from native to Java as it is no longer safe to do so. You can delay CRT shutdown via the APIs here: But if you delay it past all shutdown hooks resolving it will likely crash when the JNI boundary becomes unsafe to call. |
Beta Was this translation helpful? Give feedback.
Once the CRT's shutdown hook is executed by the JVM (presumably in response to the signal), no further callbacks are made from native to Java as it is no longer safe to do so.
You can delay CRT shutdown via the APIs here:
https://github.com/awslabs/aws-crt-java/blob/main/src/main/java/software/amazon/awssdk/crt/CRT.java#L449-L494
But if you delay it past all shutdown hooks resolving it will likely crash when the JNI boundary becomes unsafe to call.