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 inspect the WebSocket handler and its tests, then implement the error classification and add regression coverage for both malformed inputs.
- Assistant
rgisn’t installed in this checkout, so I’m using the repository’s standard file search tools as a fallback. - Assistant
The failure has two layers: the reader always emits 500, and decoded-but-invalid Base64 reaches the binary parser as an
IOException. I’m fixing both at the input boundary so every malformedmessageIdis classified as a bad query parameter. - Assistant
The code and regression tests are in place. This checkout has no Maven wrapper, so I’m switching to the installed Maven executable for the targeted module test.
- Assistant
The targeted Gradle test is still in dependency/task configuration and has produced no failures so far. I’m letting it complete, then I’ll check formatting and the final diff.
- Assistant
Gradle’s first configuration pass for this large multi-project checkout is unusually slow but remains active. The implementation itself is narrowly scoped; I’ve also confirmed the message-ID parser wraps malformed binary payloads in
IOException, which the fix converts toIllegalArgumentExceptionfor the existing 400 mapping. - Assistant
The build attempted to resolve a missing Gradle plugin remotely, so I stopped it to honor the no-internet constraint. I’ll rerun offline; if the artifact is absent locally, I’ll report that verification limitation precisely.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.