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 handlers and their tests, then patch the reader’s error classification and add regression coverage for both malformed forms.
- Assistant
rgisn’t installed in this checkout, so I’m using the repository’s standard filesystem tools as a fallback and checking local contributor instructions before editing. - Assistant
The failure has two layers: the reader hardcodes 500, and structurally invalid decoded bytes arrive as an
IOException, which the shared mapper would also classify as 500. I’m normalizing both decoding/parsing failures to an invalid-argument error, then using the shared status mapper. - Assistant
The targeted test build is running. The regression test drives the constructor through the actual query-parameter path and asserts 400 for both the space-corrupted Base64 value and the Base64-valid-but-invalid serialized value.
- Assistant
Gradle is still configuring the large multi-module build; no compilation or test failure has appeared yet. I’ll let the focused module test complete, then run the repository’s formatting/static checks relevant to these files.
- Assistant
The build is spending several minutes in Gradle task-graph calculation, with the daemon actively consuming CPU rather than reporting a failure. The code-level diff check is clean; I’m checking whether this is normal configuration work or a build-tool stall before deciding whether to restart more narrowly.
- Assistant
The thread dump shows Gradle is blocked trying to resolve a build plugin remotely. Since this task must stay offline, I’m stopping that attempt and rerunning in offline mode against the local dependency cache.
- Assistant
Offline Gradle configuration completed far enough to identify the blocker: required build dependencies (Ant, Guice, Log4j, and SLF4J artifacts) are absent from the local cache. I’m making one no-configuration-cache attempt, which avoids the cache-serialization path that triggered resolution of
buildtools; if that still needs the missing artifacts, local execution cannot proceed without network access. - Assistant
Generated protocol sources are already present from the partial build, so I can safely bypass only the unavailable generator/build-tool tasks and still compile the real module sources and regression test offline. I’m trying that now.
- Assistant
The narrowed offline build successfully compiled both
ReaderHandlerandReaderHandlerTest. Test execution itself is blocked because several test-runtime jars—including Objenesis and TestNG’s WebJar dependency—aren’t cached locally. No source or test compilation errors remain.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.