Skip to content

Direct Buffer Memory error when connecting mqtt

we are running an Apache Beam Apllication on a Flink Cluster.

Since a few days the application fails with the following error:

    Caused by: failure when writing TLS control frames
        at io.netty.handler.ssl.SslHandler.setHandshakeFailureTransportFailure(
        at io.netty.handler.ssl.SslHandler.access$600(
        at io.netty.handler.ssl.SslHandler$2.operationComplete(
        at io.netty.handler.ssl.SslHandler$2.operationComplete(
        at io.netty.util.concurrent.DefaultPromise.notifyListener0(
        at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(
        at io.netty.util.concurrent.DefaultPromise.notifyListeners(
        at io.netty.util.concurrent.DefaultPromise.addListener(
        at io.netty.handler.ssl.SslHandler.wrapNonAppData(
        at io.netty.handler.ssl.SslHandler.handshake(
        at io.netty.handler.ssl.SslHandler.startHandshakeProcessing(
        at io.netty.handler.ssl.SslHandler.channelActive(
        at io.netty.util.concurrent.SingleThreadEventExecutor$
        at io.netty.util.internal.ThreadExecutorMap$
        at java.base/
Caused by: java.lang.OutOfMemoryError: Direct buffer memory. The direct out-of-memory error has occurred. This can mean two things: either job(s) require(s) a larger size of JVM direct memory or there is a direct memory leak. The direct memory can be allocated by user code or some of its dependencies. In this case '' configuration option should be increased. Flink framework and its dependencies also consume the direct memory, mostly for network communication. The most of network memory is managed by Flink and should not result in out-of-memory error. In certain special cases, in particular for jobs with high parallelism, the framework may require more direct memory which is not managed by Flink. In this case '' configuration option should be increased. If the error persists then there is probably a direct memory leak in user code or some of its dependencies which has to be investigated and fixed. The task executor has to be shutdown...

The connection is build up with the following method:

private Mqtt5AsyncClient setupClient() {
    Mqtt5ClientBuilder mqttClientBuilder = Mqtt5Client.builder().identifier("beam-"+UUID.randomUUID().toString())
    if (properties.getUsername() != null && properties.getPassword() != null) {
      mqttClientBuilder = mqttClientBuilder.simpleAuth().username(properties.getUsername())
    } else if (properties.getUsername() != null || properties.getPassword() != null) {
      LoggerFactory.getLogger(getClass()).error("Both username and password must be provided!");

    if (properties.isSslEnabled()) { // Add ssl config if ssl is enabled
      try {
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
        ks.load(new ByteArrayInputStream(truststore), properties.getTrustStorePassword().toCharArray());


        if (properties.skipHostnameVerification()) { // Disable host name verification if required
          mqttClientBuilder = mqttClientBuilder.sslConfig().trustManagerFactory(tmf)
              .hostnameVerifier(new NoopHostnameVerifier()).applySslConfig();
        } else {
          mqttClientBuilder = mqttClientBuilder.sslConfig().trustManagerFactory(tmf).applySslConfig();
      } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException e) {
        LoggerFactory.getLogger(getClass()).error("Error while setting up ssl", e);

    Mqtt5BlockingClient newClient = mqttClientBuilder.buildBlocking();
    return newClient.toAsync();

But it runs on my machine When I start the application from my eclipse project all works fine. So the error only happen in the Flink Cluster which makes debugging a little bit difficult.

The only thing that has changed on the server was an update to openjdk-11.0.14. Updating the java on my pc to the same version doesn’t create the error at all.

So I’m running out of ideas what could cause the error.

So I checked the following things

  • Is the SSL Zertificate valid –> Yes
  • Is username and password correct –> Yes
  • Is there any logging on the mqtt side –> no

It seems the Java application fails before it could connect to the mqtt broker. Because there aren’t any login attempts on the mqtt broker.

We are using spring-boot-2.1.18 and hivemq-mqtt-client:1.2.2. The Broker is an vernemq.

Any suggestions are welcome.

Thanks in advance


So I got fixed it.

I don’t know where the problem exactly was.

I load a backup of my vm when all was working. Then I updated openjdk-11 to the latest version. After this the error appears again.

So it’s really an problem with the update to openjdk-11-jdk 11.0.14.

After deleting openjdk and make a clean reinstall all works fine again.

Maybe this will help someone.