Skip to content

Conversation

@MqllR
Copy link
Contributor

@MqllR MqllR commented Nov 25, 2025

Description

Fixes issue where concurrent JSON-RPC requests sent to the IPC socket fail with parse errors when they arrive in the same buffer as concatenated JSON objects.

Problem

When multiple requests arrive simultaneously at the IPC socket, they can be concatenated in a single buffer:

{"id":1,"method":"eth_blockNumber"}{"id":2,"method":"eth_chainId"}

The current implementation tries to parse this as either a single JsonObject or JsonArray, which fails because concatenated JSON objects are neither.

Solution

Replaced manual JSON parsing with Jackson's streaming parser (JsonParser), which can naturally handle multiple JSON objects in a stream - similar to Go's json.Decoder used in go-ethereum.

Key changes:

  • Added JsonRpcParserHandler.ipcJsonParser() using Jackson's streaming API
  • Simplified JsonRpcIpcService.java from ~300 to ~170 lines
  • Added test for concatenated requests: concatenatedJsonRequestsShouldBeHandledIndependently()

Benefits

  • ✅ Handles concurrent requests (concatenated JSON)
  • ✅ Maintains backward compatibility (single requests & batch arrays)
  • ✅ Simpler code using standard Jackson library
  • ✅ Parity with go-ethereum's IPC implementation
  • ✅ All existing tests pass + new test for concurrent requests

Testing

All 6 IPC tests pass:

✅ successfulExecution()
✅ successfulBatchExecution()
✅ validJsonButNotRpcShouldReturnInvalidRequest()
✅ nonJsonRequestShouldReturnParseError()
✅ concatenatedJsonRequestsShouldBeHandledIndependently() ← NEW
✅ shouldDeleteSocketFileOnStop()

Files Changed

  1. JsonRpcParserHandler.java - Added streaming JSON parser
  2. JsonRpcIpcService.java - Simplified to use streaming parser
  3. JsonRpcIpcServiceTest.java - Added concurrent request test

Related

This addresses the root cause discovered during investigation of why concurrent IPC requests fail while sequential requests succeed. Fixes #9495

@MqllR MqllR force-pushed the fix_ipc_concurrency branch from 135c01d to 09a3214 Compare November 25, 2025 14:21
@MqllR MqllR marked this pull request as ready for review November 25, 2025 14:23
Copilot AI review requested due to automatic review settings November 25, 2025 14:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

@jflo jflo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see performance notes, and CI is not currently passing. Once addressed, this is good to go!

public static Handler<Buffer> ipcHandler(
final BiConsumer<JsonObject, JsonArray> onParsed, final Runnable onError) {
final JsonFactory jsonFactory = new JsonFactory();
final ObjectMapper objectMapper = new ObjectMapper(jsonFactory);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JsonFactory and ObjectMappers are pretty heavyweight, these will get re-created on every ipc connection. Suggest making it a static member of the class or some other means of reuse. It is thread safe.

Copy link
Contributor Author

@MqllR MqllR Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved them as static members of the class 👍

@MqllR MqllR force-pushed the fix_ipc_concurrency branch 2 times, most recently from 4ee336a to 59a81ba Compare November 26, 2025 16:02
@MqllR MqllR requested a review from jflo November 26, 2025 16:35
Signed-off-by: Mael Regnery <mael@mqli.fr>
@MqllR MqllR force-pushed the fix_ipc_concurrency branch from 59a81ba to 8421e59 Compare November 26, 2025 16:41
@jflo jflo enabled auto-merge (squash) November 26, 2025 21:42
@jflo jflo merged commit 7d86592 into hyperledger:main Nov 26, 2025
46 checks passed
pinges pushed a commit to pinges/besu that referenced this pull request Dec 15, 2025
Signed-off-by: Mael Regnery <mael@mqli.fr>
Signed-off-by: stefan.pingel@consensys.net <stefan.pingel@consensys.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IPC JSON-RPC service fails to handle concurrent requests (concatenated JSON objects)

2 participants