Understanding and Addressing the "Deflater Has Been Closed" Exception in Java WebSocket

Hello everyone,

I’m reaching out for help regarding a recurring issue I’ve been facing with the OpenEMS WebSocket server. The error logs keep showing NullPointerException with the message “Deflater has been closed.” The error trace usually looks like this:

ERROR [socket.AbstractWebsocketServer] OnInternalError for EdgeWebsocket.WsData [edgeId=sems200]. java.lang.NullPointerException: Deflater has been closed
...
at java.util.zip.Deflater.ensureOpen(Deflater.java:898)
at java.util.zip.Deflater.deflate(Deflater.java:566)
at org.java_websocket.extensions.permessage_deflate.PerMessageDeflateExtension.encodeFrame(PerMessageDeflateExtension.java:227)
...

The Problem

From what I understand, the error occurs when the Deflater is accessed after being closed. However, I’m unsure what exactly triggers this, and why it’s happening in the WebSocket server. Here are some scenarios I’ve observed:

  • The error sometimes occurs when a client disconnects and attempts to reconnect.
  • In some cases, it happens during high-load scenarios with multiple concurrent WebSocket connections.

@stefan.feilmeier @miettal just FYI

Found out, it happens ALL the time if you edit a something in the configuration in the WebUI.