[2.x] fix: Prevent fork test cross talk (#8575)

**Problem**
currently all notifications go to all listeners.

**Solution**
This adds "re" field so we can check if it matches with the id.
This commit is contained in:
eugene yokota 2026-01-19 00:55:16 -05:00 committed by GitHub
parent 0ec5144a63
commit 215e9d6325
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View File

@ -204,7 +204,11 @@ private class React(
else if o.has("error") then promise.failure(new RuntimeException(line))
else promise.success(0)
else ()
else if o.has("method") then processNotification(o)
// per JSON-PRC notifications do not have "id" field, so we use "re"
else if o.has("re") && o.has("method") then
val resId = o.getAsJsonPrimitive("re").getAsLong()
if resId == id then processNotification(o)
else ()
else ()
catch
case _: JsonSyntaxException => log.info(line)

View File

@ -238,7 +238,8 @@ public class ForkTestMain {
String params = this.gson.toJson(info, ForkErrorInfo.class);
String notification =
String.format(
"{ \"jsonrpc\": \"2.0\", \"method\": \"forkError\", \"params\": %s }", params);
"{ \"jsonrpc\": \"2.0\", \"method\": \"forkError\", \"params\": %s, \"re\": %d }",
params, this.id);
this.originalOut.println(notification);
this.originalOut.flush();
}
@ -248,7 +249,8 @@ public class ForkTestMain {
String params = this.gson.toJson(info, TestLogInfo.class);
String notification =
String.format(
"{ \"jsonrpc\": \"2.0\", \"method\": \"testLog\", \"params\": %s }", params);
"{ \"jsonrpc\": \"2.0\", \"method\": \"testLog\", \"params\": %s, \"re\": %d }",
params, this.id);
this.originalOut.println(notification);
this.originalOut.flush();
}
@ -306,7 +308,8 @@ public class ForkTestMain {
String params = this.gson.toJson(info, ForkEventsInfo.class);
String notification =
String.format(
"{ \"jsonrpc\": \"2.0\", \"method\": \"testEvents\", \"params\": %s }", params);
"{ \"jsonrpc\": \"2.0\", \"method\": \"testEvents\", \"params\": %s, \"re\": %d }",
params, this.id);
this.originalOut.println(notification);
this.originalOut.flush();
}