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 existing tests, then patch the error classification and add regression coverage for both malformed message ID forms.
- Assistant
rgisn’t installed in this checkout environment, so I’m switching tofind/grepand keeping the search scoped to the WebSocket module. - Assistant
The second input is syntactically valid Base64, so changing only the constructor’s status mapping would still leave it as 500 because deserialization throws
IOException. I’m normalizing both decode/deserialization failures toIllegalArgumentException, then using the shared handler mapping so both paths become 400. - Assistant
The first test command used the directory name as the Maven reactor selector, but this module is registered under a different reactor identity. I’m resolving its artifact/module path and will rerun the focused test from the correct build context.
- Assistant
The focused Gradle test is still in dependency/configuration setup and hasn’t reported a compile or test failure. The implementation and regression test diff already pass whitespace validation; I’m continuing through the module test run.
- Assistant
Gradle has remained in task-graph calculation for several minutes with no task execution, consistent with dependency/plugin resolution in this fresh checkout. Since this task must stay offline, I’m stopping that run and retrying in explicit offline mode so it either uses local caches or fails clearly.
- Assistant
The offline run failed before compiling this module because the repository’s configuration cache tries to resolve uncached
buildtoolsdependencies. I’m retrying offline with configuration-cache disabled; that avoids the unrelated cache-serialization resolution and may allow the focused module graph to run from what is locally available. - Assistant
The focused test sources now compile successfully offline. The missing dependencies are isolated to the repository’s unrelated
buildtoolscompile task, so I’m excluding that task and running the actualReaderHandlerTestsuite.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.