Commit e39cf04
authored
feat(gradle-server): migrate task transport from gRPC to JSON-RPC over TCP loopback (PR 1/3) (#1863)
* feat(gradle-server): migrate task transport from gRPC to JSON-RPC over TCP loopback
Replace the existing gRPC + Netty HTTP/2 transport for the task server with
LSP4J JSON-RPC over a plain TCP loopback socket. This eliminates the
mid-frame HTTP/2 race (vscode-gradle issue #1815) at its source by removing
the Netty stack from the task-server hot path entirely.
What changes on the gradle-server side
- New package ransport.jsonrpc exposing six methods on gradle/ segment:
getBuild, runBuild, getProjectDependencies, cancelBuild, cancelBuilds,
executeCommand. Streaming RPCs (getBuild/runBuild) deliver intermediate
progress through gradle/getBuild/reply and gradle/runBuild/reply
notifications and complete the JSON-RPC request with the terminal reply.
- Protobuf wire schema (proto/gradle.proto) is reused for payload bytes;
request/response/notification params carry the base64-encoded proto
bytes plus a stream id. This keeps the message layer stable across the
migration and avoids a JSON re-encoding of large progress payloads.
- GradleServer becomes a thin bootstrap: it connects out to the Node
listener on 127.0.0.1:<port>, builds an LSP4J launcher backed by a
cached worker pool, and blocks until the socket closes.
- Handlers no longer hold gRPC StreamObservers. Streaming handlers take
(Request, CompletableFuture<GradleResponse>, GradleClient, long streamId);
unary handlers take (Request, CompletableFuture<GradleResponse>).
Removed
- io.grpc:grpc-protobuf, grpc-stub, grpc-netty (plus grpc-testing)
dependencies, the protoc-gen-grpc-java plugin, and the
�uild/generated/source/proto/main/grpc source set.
- TaskService (gRPC service shim) and ErrorMessageBuilder (only used
by the gRPC error path).
- The Netty HTTP/2 mid-frame log filter and its tests
(GradleServerFilterTest).
- Forced
etty-bom pin (no longer relevant since Netty is gone from
the task-server runtime).
Tests
- GradleServerTest now exercises handlers directly via
CompletableFuture<GradleResponse> and a Mockito-mocked GradleClient,
so the test surface verifies Gradle Tooling API interactions without
spinning up a gRPC InProcess channel.
- One extra --add-opens (java.util.concurrent) is added to the test
JVM args so PowerMock can introspect CompletableFuture on JDK 17+.
This commit is the gradle-server half of the migration. The TypeScript
extension still speaks gRPC and is updated in PR 2; the proto files and
the root-build grpcVersion constant are cleaned up in PR 3.
* test(gradle-server): cover JSON-RPC transport with end-to-end roundtrip tests
Add JsonRpcTransportTest exercising the new transport package end-to-end
over a pair of piped streams. Two Launcher instances are wired together
(server side: GradleService stub + GradleClient remote proxy; client
side: recording GradleClient + GradleService remote proxy) so the full
request/response/notification path is driven without a real socket and
without a dependency on the Gradle Tooling API.
Coverage:
- Base64 protobuf encode/decode roundtrip via JsonRpcCodec.
- All six RPC methods (getBuild,
unBuild, getProjectDependencies,
cancelBuild, cancelBuilds, �xecuteCommand) — payload identity,
stream-id propagation, and null
eply handling.
- Streaming notifications: getBuild/reply carries the right stream id
and payload to the client side;
unBuild/reply is delivered on the
separate
unBuild notification channel without leaking into the
getBuild channel.
- Error mapping across the wire for ResponseErrorException produced by
JsonRpcCodec.error(...) — covers NOT_FOUND, CANCELLED and
INTERNAL (the last one via a Throwable carrier).
- Pinned constants for the four error codes that form part of the wire
contract with the TS client, to catch accidental renumbering.
The handler-level behaviour (Gradle Tooling API interaction, debug init
script, JVM args, etc.) stays covered by GradleServerTest, which talks
to handlers directly via CompletableFuture<GradleResponse> rather than
through the JSON-RPC dispatch layer — so the two test classes between
them cover the wire layer and the business logic without overlapping.
* fix: update the review comments
* fix(gradle-server): address Copilot review comments on PR #1863
- GradleServiceImpl: validate JSON-RPC params/request nullability and map
Base64 decode errors to ERROR_UNKNOWN instead of ERROR_INTERNAL so
client-side input bugs surface with the correct wire code.
- ExecuteCommandHandler: split error replies so unknown commands return
ERROR_NOT_FOUND and argument-count violations return ERROR_UNKNOWN;
reserve ERROR_INTERNAL for genuine server failures.
- GradleServer: extract a workerThreadFactory() that hands out unique
`gradle-jsonrpc-worker-N` names via AtomicInteger so concurrent
handlers are distinguishable in thread dumps and logs.
Adds regression coverage:
- JsonRpcTransportTest: 4 new tests for null params, null request,
invalid Base64, and null cancelBuilds params.
- ExecuteCommandHandlerTest (new): 4 tests covering the new error code
mapping plus the happy path.
- GradleServerThreadFactoryTest (new): 3 tests covering unique naming,
daemon flag, and per-instance counter isolation.
* perf: improve sync lock and order code
* perf: error code
* chore: ignore local-only *.local.md working notes1 parent e916b25 commit e39cf04
24 files changed
Lines changed: 1456 additions & 527 deletions
File tree
- gradle-server
- src
- main/java/com/github/badsyntax/gradle
- handlers
- transport/jsonrpc
- test/java/com/github/badsyntax/gradle
- handlers
- transport/jsonrpc
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | | - | |
29 | | - | |
30 | | - | |
| 27 | + | |
31 | 28 | | |
32 | 29 | | |
33 | 30 | | |
34 | 31 | | |
35 | 32 | | |
36 | | - | |
37 | 33 | | |
38 | 34 | | |
39 | 35 | | |
| |||
51 | 47 | | |
52 | 48 | | |
53 | 49 | | |
54 | | - | |
55 | 50 | | |
56 | 51 | | |
57 | 52 | | |
| |||
61 | 56 | | |
62 | 57 | | |
63 | 58 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | 59 | | |
75 | 60 | | |
76 | 61 | | |
77 | 62 | | |
78 | 63 | | |
79 | 64 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | 65 | | |
84 | 66 | | |
85 | 67 | | |
| |||
157 | 139 | | |
158 | 140 | | |
159 | 141 | | |
| 142 | + | |
160 | 143 | | |
161 | 144 | | |
162 | 145 | | |
| |||
Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 40 additions & 105 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | 7 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
17 | 12 | | |
18 | 13 | | |
19 | 14 | | |
20 | 15 | | |
21 | 16 | | |
22 | 17 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 18 | + | |
64 | 19 | | |
65 | 20 | | |
66 | 21 | | |
67 | | - | |
68 | | - | |
69 | 22 | | |
70 | 23 | | |
71 | 24 | | |
| |||
84 | 37 | | |
85 | 38 | | |
86 | 39 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | 40 | | |
134 | | - | |
| 41 | + | |
135 | 42 | | |
| 43 | + | |
136 | 44 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
141 | 54 | | |
142 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
143 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
144 | 64 | | |
145 | 65 | | |
146 | 66 | | |
| |||
155 | 75 | | |
156 | 76 | | |
157 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
158 | 93 | | |
Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 12 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | | - | |
| 17 | + | |
16 | 18 | | |
17 | | - | |
| 19 | + | |
18 | 20 | | |
19 | | - | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | | - | |
30 | | - | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
41 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
0 commit comments