Untitled conversation
- User
[Bug] WebSocket ReaderHandler returns 500 for invalid messageId query parameter
Search before reporting
- I searched in the issues and found nothing similar.
Read release policy
- I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.
User environment
Broker Version 4.0.7 Any broker OS Any broker Java version Any WebSocket client
Issue Description
Minimal reproduction steps
Connect to the WebSocket reader endpoint with an invalid
messageIdquery parameter.Two examples that both trigger the bug:
-
An improperly URL-encoded base64 message ID that includes a
+which the server interprets as a space (e.g.CJCj6QEQ+UQwAA==becomesCJCj6QEQ UQwAA==). -
An arbitrary non-base64 string:
?messageId=invalidMessageId
What did you expect to see?
HTTP 400 Bad Request.
What did you see instead?
HTTP 500 Internal Server Error in both cases.
Case 1 —
IllegalArgumentExceptionfromBase64.getDecoder().decode():WARN org.apache.pulsar.websocket.ReaderHandler - [REDACTED] Failed in creating reader on topic persistent://REDACTED/REDACTED/REDACTED java.lang.IllegalArgumentException: Illegal base64 character 20 at java.base/java.util.Base64$Decoder.decode0(Unknown Source) ~[?:?] at java.base/java.util.Base64$Decoder.decode(Unknown Source) ~[?:?] at java.base/java.util.Base64$Decoder.decode(Unknown Source) ~[?:?] at org.apache.pulsar.websocket.ReaderHandler.getMessageId(ReaderHandler.java:348) ~[org.apache.pulsar-pulsar-websocket-4.0.7.jar:4.0.7] at org.apache.pulsar.websocket.ReaderHandler.<init>(ReaderHandler.java:95) ~[org.apache.pulsar-pulsar-websocket-4.0.7.jar:4.0.7] at org.apache.pulsar.websocket.WebSocketReaderServlet.lambda$configure$0(WebSocketReaderServlet.java:44) ~[org.apache.pulsar-pulsar-websocket-4.0.7.jar:4.0.7]Case 2 —
IOExceptionwrappingIndexOutOfBoundsExceptionfrom : - Assistant
I’ll trace the WebSocket handler and its existing tests, then patch the error classification and add focused regression coverage for both malformed inputs.
- Assistant
rgisn’t installed in this checkout, so I’m using the repository’s standard shell tools to locate the implementation and nearest test patterns. - Assistant
The failure has two layers: the reader catch always emits 500, and malformed decoded bytes arrive as
IOException, which the shared classifier would still treat as 500. I’m addressing both by normalizing message-ID parse failures to an invalid-argument error and using the shared response mapping. - Assistant
The regression test now exercises both reported inputs through the constructor and verifies HTTP 400. The focused Gradle test is compiling/running; I also removed the import made obsolete by the shared classifier.
- Assistant
Gradle is still actively resolving the large multi-module task graph (the daemon is consuming CPU, not stalled). While it finishes, I’m checking the diff for style and whether the test can assert the standardized error message as well as the status.
- Assistant
The build entered an external dependency connection attempt during configuration, which is outside the requested offline constraint. I’m stopping that attempt and will rerun in Gradle offline mode against the local cache.
- Assistant
The offline run confirms the test task is blocked only by uncached build dependencies (
ant,guice, and logging artifacts). The source inspection confirms this branch wraps malformed protobuf bytes inIOException, so the normalization covers the second reproduction exactly. I’m tightening the assertion to check the safe standardized error text too.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.