IconServlet: Remove error & warn logging when client disconnected while sending response (#5257)

When a client disconnected while receiving the icon byte stream response,
an error and a warning were logged, making users worried:

```
2022-08-15 20:09:31.387 [ERROR] [ab.core.ui.icon.internal.IconServlet] - Failed sending the icon byte stream as a response: null
2022-08-15 20:09:31.390 [WARN ] [org.eclipse.jetty.server.HttpChannel] - /icon/autarky
java.lang.IllegalStateException: ABORTED
	at org.eclipse.jetty.server.HttpChannelState.sendError(HttpChannelState.java:915) ~[?:?]
    ...
```

IMO, there is no need to log at ERROR or WARN level in such cases,
so I decided to reduce to DEBUG logging.

The following script can be used to reproduce the above case:

```python
import socket
import struct

host = 'localhost'
port = 8080
path = '/icon/BatteryLevel?format=svg&anyFormat=true&state=94+%25&iconset=classic'
request = f"GET {path} HTTP/1.1\r\nHost: {host}\r\nConnection: keep-alive\r\n\r\n"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))

# Send the request
s.sendall(request.encode())

# FORCE an immediate hard reset (RST)
# This ensures the server sees a connection failure while it's inside doGet
s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', 1, 0))
s.close()
```

Signed-off-by: Florian Hotze <dev@florianhotze.com>
This commit is contained in:
Florian Hotze
2026-01-17 19:45:21 +01:00
committed by GitHub
parent d0c3b4a4ec
commit aff119cd19
@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.io.EofException;
import org.openhab.core.ui.icon.IconProvider;
import org.openhab.core.ui.icon.IconSet.Format;
import org.osgi.service.component.annotations.Activate;
@@ -145,6 +146,12 @@ public class IconServlet extends HttpServlet {
is.transferTo(resp.getOutputStream());
resp.flushBuffer();
} catch (IOException e) {
if (resp.isCommitted() && e instanceof EofException) {
logger.debug("Client {} disconnected while sending the icon byte stream as response",
req.getRemoteAddr());
// don't send a response as client is already gone
return;
}
logger.error("Failed sending the icon byte stream as a response: {}", e.getMessage());
resp.sendError(500, e.getMessage());
}