Repository navigation
fix(#4801): serialize gRPC streaming terminal calls on a thread-safe StreamObserver - #4818
Conversation
…treamObserver
graphBatchLoad and insertBidirectional issued onNext/onError/onCompleted
directly on a non-thread-safe StreamObserver. A cancellation racing a final
terminal call, or a duplicate terminal, could interleave terminal calls and
throw IllegalStateException ("call already closed"), drop responses, or hang
the client.
Introduce SynchronizedStreamObserver: serializes every call, enforces at most
one delegated terminal via an AtomicBoolean CAS, drops onNext after terminal,
exposes markTerminated() for the cancel handler, and swallows the delegate's
IllegalStateException on concurrent close. Both streaming handlers now route
all write/terminal calls through it.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Tick the box to add this pull request to the merge queue (same as
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 14 |
🟢 Coverage 70.59% diff coverage · -7.28% coverage variation
Metric Results Coverage variation ✅ -7.28% coverage variation Diff coverage ✅ 70.59% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (61d0b69) 133245 98847 74.18% Head commit (0f89c86) 165096 (+31851) 110459 (+11612) 66.91% (-7.28%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#4818) 68 48 70.59% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Code Review
This pull request addresses issue #4801 by introducing SynchronizedStreamObserver, a thread-safe wrapper for gRPC's StreamObserver to prevent concurrent terminal calls and race conditions in graphBatchLoad and insertBidirectional. It also adds a comprehensive suite of unit tests to verify thread safety and contract enforcement. The review feedback suggests a valuable improvement: catching io.grpc.StatusRuntimeException alongside IllegalStateException in onNext, onError, and onCompleted to ensure transport-level exceptions from cancelled or closed calls do not propagate unexpectedly.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| public void onNext(final T value) { | ||
| synchronized (lock) { | ||
| if (completed.get()) | ||
| return; | ||
| try { | ||
| delegate.onNext(value); | ||
| } catch (final IllegalStateException closed) { | ||
| // The underlying call was concurrently cancelled/closed by the transport: stop sending. | ||
| completed.set(true); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
In addition to IllegalStateException, gRPC's StreamObserver can throw io.grpc.StatusRuntimeException (e.g., with status CANCELLED) if the call is cancelled or closed by the transport. Catching StatusRuntimeException ensures that the wrapper immediately marks itself as completed and avoids redundant subsequent calls to the delegate.
| public void onNext(final T value) { | |
| synchronized (lock) { | |
| if (completed.get()) | |
| return; | |
| try { | |
| delegate.onNext(value); | |
| } catch (final IllegalStateException closed) { | |
| // The underlying call was concurrently cancelled/closed by the transport: stop sending. | |
| completed.set(true); | |
| } | |
| } | |
| } | |
| @Override | |
| public void onNext(final T value) { | |
| synchronized (lock) { | |
| if (completed.get()) | |
| return; | |
| try { | |
| delegate.onNext(value); | |
| } catch (final IllegalStateException | io.grpc.StatusRuntimeException closed) { | |
| // The underlying call was concurrently cancelled/closed by the transport: stop sending. | |
| completed.set(true); | |
| } | |
| } | |
| } |
| public void onError(final Throwable t) { | ||
| synchronized (lock) { | ||
| if (!completed.compareAndSet(false, true)) | ||
| return; | ||
| try { | ||
| delegate.onError(t); | ||
| } catch (final IllegalStateException ignore) { | ||
| // Call already closed: nothing more to deliver. | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Catching io.grpc.StatusRuntimeException here as well prevents transport-level exceptions from propagating when trying to deliver an error on an already closed or cancelled call.
| public void onError(final Throwable t) { | |
| synchronized (lock) { | |
| if (!completed.compareAndSet(false, true)) | |
| return; | |
| try { | |
| delegate.onError(t); | |
| } catch (final IllegalStateException ignore) { | |
| // Call already closed: nothing more to deliver. | |
| } | |
| } | |
| } | |
| @Override | |
| public void onError(final Throwable t) { | |
| synchronized (lock) { | |
| if (!completed.compareAndSet(false, true)) | |
| return; | |
| try { | |
| delegate.onError(t); | |
| } catch (final IllegalStateException | io.grpc.StatusRuntimeException ignore) { | |
| // Call already closed: nothing more to deliver. | |
| } | |
| } | |
| } |
| public void onCompleted() { | ||
| synchronized (lock) { | ||
| if (!completed.compareAndSet(false, true)) | ||
| return; | ||
| try { | ||
| delegate.onCompleted(); | ||
| } catch (final IllegalStateException ignore) { | ||
| // Call already closed: nothing more to deliver. | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Catching io.grpc.StatusRuntimeException here as well prevents transport-level exceptions from propagating when trying to complete an already closed or cancelled call.
| public void onCompleted() { | |
| synchronized (lock) { | |
| if (!completed.compareAndSet(false, true)) | |
| return; | |
| try { | |
| delegate.onCompleted(); | |
| } catch (final IllegalStateException ignore) { | |
| // Call already closed: nothing more to deliver. | |
| } | |
| } | |
| } | |
| @Override | |
| public void onCompleted() { | |
| synchronized (lock) { | |
| if (!completed.compareAndSet(false, true)) | |
| return; | |
| try { | |
| delegate.onCompleted(); | |
| } catch (final IllegalStateException | io.grpc.StatusRuntimeException ignore) { | |
| // Call already closed: nothing more to deliver. | |
| } | |
| } | |
| } |
Review: fix(#4801) serialize gRPC streaming terminal callsSolid, well-scoped fix. The Main observation: the fix looks incomplete
call.setOnCancelHandler(() -> cancelled.set(true));
...
if (!cancelled.get()) { // <-- cancellation can win between check and the calls below
resp.onNext(ctx.summary(totals, startedAt));
resp.onCompleted();
}
...
resp.onError(Status.INTERNAL.withDescription("insertStream: " + e.getMessage()).asException());This is the identical Code quality / correctness
PerformanceNegligible: one monitor + one SecurityNo concerns. No new dependencies, no change to auth/credential paths, error messages unchanged. Test coverageStrong for the wrapper in isolation. Two suggestions:
Overall: good fix, good tests. The main actionable item is deciding whether |
…tStream Review feedback: - gemini: gRPC can throw StatusRuntimeException (e.g. CANCELLED) on write/close after the transport closes the call, not only IllegalStateException. Widen the guarded delegate catch blocks to a multi-catch. - claude: insertStream had the identical TOCTOU cancel-vs-terminal race; wrap its response observer in SynchronizedStreamObserver too for consistency. - Add a happy-path test asserting exactly one terminal reaches the delegate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks for the reviews. Addressed in f785c9d:
Verified: |
|
Thanks for the update, @robfrank. The inclusion of |
Review: PR #4818 - serialize gRPC streaming terminal callsThanks for the careful writeup and the red/green-verified tests. The core design is sound and the fix directly addresses the TOCTOU Strengths
Observations / possible follow-ups (non-blocking)
Style / conventionsAligns with CLAUDE.md: VerdictLooks good to merge. The fix is correct and well-tested; the items above are follow-up hygiene rather than blockers. The one to keep on the radar is #1 - the query-streaming terminal path is the remaining instance of the same race class. |
Review (cycle 2) clarity-only follow-ups: document why markTerminated() is deliberately lock-free (cancel handler must not block behind an in-flight onNext), and note that graphBatchLoad's errorSent flag only gates the onCompleted flush and flow-control pull while SynchronizedStreamObserver independently guarantees terminal-call safety. No behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks for the cycle-2 pass. Addressed the clarity items in cfe87b4 (comment-only, no behavior change):
On the non-blocking follow-ups:
Verified after the change: grpcw test-compile clean; unit + the two ITs unchanged. |
Code Review - PR #4818 (fix #4801: serialize gRPC streaming terminal calls)Reviewed the new Strengths
Points worth a look
Performance / security
Nice work - the fix is correct, the rationale is well documented in code, and the regression coverage is solid. Item #1 is the only one I'd consider acting on before merge; #2 is a good follow-up. |
Review (cycle 3): when delegate.onNext throws, the wrapper previously marked itself terminated without delivering any terminal. For an already-closed call that is correct, but a still-live call that rejects a single message (e.g. RESOURCE_EXHAUSTED) would leave the client hanging. onNext now best-effort delivers onError on that path (compareAndSet skips it if markTerminated already fired; an already-closed call swallows the no-op onError). Adds a regression test for the live-but-rejecting-write path. Unit suite 7/7. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks - acted on item #1 in 0f89c86. Item #2 ( |
|
Review: fix(#4801) - serialize gRPC streaming terminal calls Solid, well-scoped fix with an accurate root-cause analysis. The Correctness - looks sound
Minor / discussion points (non-blocking)
Style / conventions
Note: I reviewed statically and did not rebuild locally; the PR documents the unit suite (7/7) and Overall: LGTM. The thread-safety guarantee is correct and the test coverage backing it is strong. The points above are refinements, not blockers. |
|
Thanks for the LGTM. Noting the cycle-4 refinements for the record:
Final state: unit suite 7/7, |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4818 +/- ##
============================================
- Coverage 65.19% 65.18% -0.02%
+ Complexity 716 715 -1
============================================
Files 1680 1681 +1
Lines 133245 133293 +48
Branches 28482 28486 +4
============================================
+ Hits 86867 86881 +14
- Misses 34435 34465 +30
- Partials 11943 11947 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…io with 2 updates [skip ci] Bumps the build-tools group in /studio with 2 updates: [webpack](https://github.com/webpack/webpack) and [webpack-cli](https://github.com/webpack/webpack-cli). Updates `webpack` from 5.109.0 to 5.109.2 Release notes *Sourced from [webpack's releases](https://github.com/webpack/webpack/releases).* > v5.109.2 > -------- > > ### Patch Changes > > * Resolve aliases pointing at a package directory whose name ends with `.js` again. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21542](https://redirect.github.com/webpack/webpack/pull/21542)) > * Name CSS sources in source maps by their resource path, without the `css` prefix. (by [`@bjohansebas`](https://github.com/bjohansebas) in [#21536](https://redirect.github.com/webpack/webpack/pull/21536)) > * Delete no longer referenced files from the filesystem cache directory after storing the cache, age them by recorded time so restored caches are cleaned too, and collect every fully expired pack in one store instead of one per build. (by [`@bjohansebas`](https://github.com/bjohansebas) in [#21528](https://redirect.github.com/webpack/webpack/pull/21528)) > * Report `"universal"` as the loader context target for the universal target. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21540](https://redirect.github.com/webpack/webpack/pull/21540)) > * Skip `require().prop` in dead branches gated by inlined imported constants. (by [`@hai-x`](https://github.com/hai-x) in [#21517](https://redirect.github.com/webpack/webpack/pull/21517)) > * Annotate configuration options and public hooks in the generated types with the `@since` JSDoc tag. (by [`@bjohansebas`](https://github.com/bjohansebas) in [#21473](https://redirect.github.com/webpack/webpack/pull/21473)) > > v5.109.1 > -------- > > ### Patch Changes > > * Fix stray semicolon emitted before an imported call following a parenthesized sequence element. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21533](https://redirect.github.com/webpack/webpack/pull/21533)) > * Make `require(esm)` `module.exports` re-export analysis independent of module processing order. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21521](https://redirect.github.com/webpack/webpack/pull/21521)) > * Ignore ERR\_SERVER\_NOT\_RUNNING on lazy-compilation backend dispose so `compiler.close()` succeeds on Bun. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21521](https://redirect.github.com/webpack/webpack/pull/21521)) > * Name the failing key when DefinePlugin fails to evaluate a `typeof` value. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21503](https://redirect.github.com/webpack/webpack/pull/21503)) > * Improve Deno compatibility: guard `setNoDelay` and force-close connections on lazy-compilation backend dispose, and return a real `ArrayBuffer` from the Node async/sync wasm loader so `WebAssembly.instantiate` accepts it. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21524](https://redirect.github.com/webpack/webpack/pull/21524)) > * Speed up the HTML parser and cut its peak memory: module-scope helpers/state and tokenizer callbacks, plus exact AST column pre-sizing. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21492](https://redirect.github.com/webpack/webpack/pull/21492)) > * Track CommonJS build dependencies by parsing sources when `require.cache` children are unavailable (e.g. Bun). (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21531](https://redirect.github.com/webpack/webpack/pull/21531)) > * Cook common string-literal escapes on the JS parser fast path and own the tokenizer's cold-path readers. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21500](https://redirect.github.com/webpack/webpack/pull/21500)) > * Build the CSS `parseA*` AST on the SoA store instead of node classes, cutting parse memory and time. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21498](https://redirect.github.com/webpack/webpack/pull/21498)) > * Speed up and cut memory of the experimental CSS and HTML parsers: drop two derivable AST node columns, and scan long string, url, comment, and plaintext token bodies natively. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21504](https://redirect.github.com/webpack/webpack/pull/21504)) > * Speed up non-modules CSS parsing: skip redundant token re-reads, drop selector-prelude tokens without materializing nodes, allocate rule preludes lazily, and fast-path empty list seals. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21511](https://redirect.github.com/webpack/webpack/pull/21511)) > * Speed up stats generation and cut its peak memory: reuse cached sort comparators instead of thrashing the comparator caches on every sort, and drop redundant module-graph lookups and allocations in the extractors. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21506](https://redirect.github.com/webpack/webpack/pull/21506)) > * Speed up CSS parsing: byte-range function-name checks, indexed sibling lookahead. (by [`@bjohansebas`](https://github.com/bjohansebas) in [#21520](https://redirect.github.com/webpack/webpack/pull/21520)) > * Reduce allocations and redundant work across the code-generation, module-concatenation, exports/usage-analysis, hashing, and chunk-splitting hot paths. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21516](https://redirect.github.com/webpack/webpack/pull/21516)) > * Enable the Node.js compile cache in the webpack CLI entry point. (by [`@bjohansebas`](https://github.com/bjohansebas) in [#21523](https://redirect.github.com/webpack/webpack/pull/21523)) > * Encode the persistent cache with V8's value serializer. (by [`@avivkeller`](https://github.com/avivkeller) in [#21514](https://redirect.github.com/webpack/webpack/pull/21514)) ... (truncated) Changelog *Sourced from [webpack's changelog](https://github.com/webpack/webpack/blob/main/CHANGELOG.md).* > 5.109.2 > ------- > > ### Patch Changes > > * Resolve aliases pointing at a package directory whose name ends with `.js` again. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21542](https://redirect.github.com/webpack/webpack/pull/21542)) > * Name CSS sources in source maps by their resource path, without the `css` prefix. (by [`@bjohansebas`](https://github.com/bjohansebas) in [#21536](https://redirect.github.com/webpack/webpack/pull/21536)) > * Delete no longer referenced files from the filesystem cache directory after storing the cache, age them by recorded time so restored caches are cleaned too, and collect every fully expired pack in one store instead of one per build. (by [`@bjohansebas`](https://github.com/bjohansebas) in [#21528](https://redirect.github.com/webpack/webpack/pull/21528)) > * Report `"universal"` as the loader context target for the universal target. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21540](https://redirect.github.com/webpack/webpack/pull/21540)) > * Skip `require().prop` in dead branches gated by inlined imported constants. (by [`@hai-x`](https://github.com/hai-x) in [#21517](https://redirect.github.com/webpack/webpack/pull/21517)) > * Annotate configuration options and public hooks in the generated types with the `@since` JSDoc tag. (by [`@bjohansebas`](https://github.com/bjohansebas) in [#21473](https://redirect.github.com/webpack/webpack/pull/21473)) > > 5.109.1 > ------- > > ### Patch Changes > > * Fix stray semicolon emitted before an imported call following a parenthesized sequence element. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21533](https://redirect.github.com/webpack/webpack/pull/21533)) > * Make `require(esm)` `module.exports` re-export analysis independent of module processing order. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21521](https://redirect.github.com/webpack/webpack/pull/21521)) > * Ignore ERR\_SERVER\_NOT\_RUNNING on lazy-compilation backend dispose so `compiler.close()` succeeds on Bun. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21521](https://redirect.github.com/webpack/webpack/pull/21521)) > * Name the failing key when DefinePlugin fails to evaluate a `typeof` value. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21503](https://redirect.github.com/webpack/webpack/pull/21503)) > * Improve Deno compatibility: guard `setNoDelay` and force-close connections on lazy-compilation backend dispose, and return a real `ArrayBuffer` from the Node async/sync wasm loader so `WebAssembly.instantiate` accepts it. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21524](https://redirect.github.com/webpack/webpack/pull/21524)) > * Speed up the HTML parser and cut its peak memory: module-scope helpers/state and tokenizer callbacks, plus exact AST column pre-sizing. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21492](https://redirect.github.com/webpack/webpack/pull/21492)) > * Track CommonJS build dependencies by parsing sources when `require.cache` children are unavailable (e.g. Bun). (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21531](https://redirect.github.com/webpack/webpack/pull/21531)) > * Cook common string-literal escapes on the JS parser fast path and own the tokenizer's cold-path readers. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21500](https://redirect.github.com/webpack/webpack/pull/21500)) > * Build the CSS `parseA*` AST on the SoA store instead of node classes, cutting parse memory and time. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21498](https://redirect.github.com/webpack/webpack/pull/21498)) > * Speed up and cut memory of the experimental CSS and HTML parsers: drop two derivable AST node columns, and scan long string, url, comment, and plaintext token bodies natively. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21504](https://redirect.github.com/webpack/webpack/pull/21504)) > * Speed up non-modules CSS parsing: skip redundant token re-reads, drop selector-prelude tokens without materializing nodes, allocate rule preludes lazily, and fast-path empty list seals. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21511](https://redirect.github.com/webpack/webpack/pull/21511)) > * Speed up stats generation and cut its peak memory: reuse cached sort comparators instead of thrashing the comparator caches on every sort, and drop redundant module-graph lookups and allocations in the extractors. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21506](https://redirect.github.com/webpack/webpack/pull/21506)) > * Speed up CSS parsing: byte-range function-name checks, indexed sibling lookahead. (by [`@bjohansebas`](https://github.com/bjohansebas) in [#21520](https://redirect.github.com/webpack/webpack/pull/21520)) > * Reduce allocations and redundant work across the code-generation, module-concatenation, exports/usage-analysis, hashing, and chunk-splitting hot paths. (by [`@alexander-akait`](https://github.com/alexander-akait) in [#21516](https://redirect.github.com/webpack/webpack/pull/21516)) > * Enable the Node.js compile cache in the webpack CLI entry point. (by [`@bjohansebas`](https://github.com/bjohansebas) in [#21523](https://redirect.github.com/webpack/webpack/pull/21523)) ... (truncated) Commits * [`6a24bd6`](webpack/webpack@6a24bd6) chore(release): new release ([#21534](https://redirect.github.com/webpack/webpack/issues/21534)) * [`d1b5b6d`](webpack/webpack@d1b5b6d) fix: resolve aliases pointing at a package directory ending in .js ([#21542](https://redirect.github.com/webpack/webpack/issues/21542)) * [`9cdcc57`](webpack/webpack@9cdcc57) fix(target): report "universal" as the loader target ([#21540](https://redirect.github.com/webpack/webpack/issues/21540)) * [`774e7e4`](webpack/webpack@774e7e4) feat: annotate schema options with added keywords ([#21473](https://redirect.github.com/webpack/webpack/issues/21473)) * [`ff07bdc`](webpack/webpack@ff07bdc) fix(css): name CSS sources in source maps by their resource path ([#21536](https://redirect.github.com/webpack/webpack/issues/21536)) * [`d56d82d`](webpack/webpack@d56d82d) fix(cache): reclaim stale filesystem cache files reliably ([#21539](https://redirect.github.com/webpack/webpack/issues/21539)) * [`ae67e2a`](webpack/webpack@ae67e2a) chore(readme): add codspeed ([#21497](https://redirect.github.com/webpack/webpack/issues/21497)) * [`964bbfa`](webpack/webpack@964bbfa) fix: delete no longer referenced files from the filesystem cache directory (#... * [`075d0cd`](webpack/webpack@075d0cd) feat: skip `require().prop` in dead branches ([#21517](https://redirect.github.com/webpack/webpack/issues/21517)) * [`ec39088`](webpack/webpack@ec39088) chore(release): new release ([#21493](https://redirect.github.com/webpack/webpack/issues/21493)) * Additional commits viewable in [compare view](webpack/webpack@v5.109.0...v5.109.2) Updates `webpack-cli` from 7.2.1 to 7.2.2 Release notes *Sourced from [webpack-cli's releases](https://github.com/webpack/webpack-cli/releases).* > webpack-cli@7.2.2 > ----------------- > > ### Patch Changes > > * perf: enable the Node.js compile cache (`module.enableCompileCache`, available on Node.js >= 22.8.0) to speed up CLI startup (by [`@bjohansebas`](https://github.com/bjohansebas) in [#4818](https://redirect.github.com/webpack/webpack-cli/pull/4818)) Changelog *Sourced from [webpack-cli's changelog](https://github.com/webpack/webpack-cli/blob/main/CHANGELOG.md).* > 7.2.2 > ----- > > ### Patch Changes > > * perf: enable the Node.js compile cache (`module.enableCompileCache`, available on Node.js >= 22.8.0) to speed up CLI startup (by [`@bjohansebas`](https://github.com/bjohansebas) in [#4818](https://redirect.github.com/webpack/webpack-cli/pull/4818)) Commits * [`191fa9f`](webpack/webpack-cli@191fa9f) chore(release): new release ([#4820](https://redirect.github.com/webpack/webpack-cli/issues/4820)) * [`1082235`](webpack/webpack-cli@1082235) chore(deps-dev): bump js-yaml from 5.2.1 to 5.2.2 ([#4821](https://redirect.github.com/webpack/webpack-cli/issues/4821)) * [`e36ae82`](webpack/webpack-cli@e36ae82) chore: add publish workflow and script for pkg.pr.new integration ([#4819](https://redirect.github.com/webpack/webpack-cli/issues/4819)) * [`b0a2024`](webpack/webpack-cli@b0a2024) perf: enable the Node.js compile cache ([#4818](https://redirect.github.com/webpack/webpack-cli/issues/4818)) * [`53f6d72`](webpack/webpack-cli@53f6d72) chore(deps): bump actions/checkout in the dependencies group ([#4816](https://redirect.github.com/webpack/webpack-cli/issues/4816)) * [`8856346`](webpack/webpack-cli@8856346) chore: add allowscripts to work with npm 12 ([#4811](https://redirect.github.com/webpack/webpack-cli/issues/4811)) * [`0b0f1ee`](webpack/webpack-cli@0b0f1ee) chore(deps): bump fast-uri from 3.1.2 to 3.1.4 ([#4815](https://redirect.github.com/webpack/webpack-cli/issues/4815)) * [`d60a777`](webpack/webpack-cli@d60a777) chore(deps-dev): bump postcss from 8.5.10 to 8.5.22 ([#4814](https://redirect.github.com/webpack/webpack-cli/issues/4814)) * [`8c1719a`](webpack/webpack-cli@8c1719a) chore(deps): bump shell-quote from 1.8.4 to 1.10.0 ([#4813](https://redirect.github.com/webpack/webpack-cli/issues/4813)) * [`8c2473c`](webpack/webpack-cli@8c2473c) chore(deps): bump immutable from 5.1.5 to 5.1.9 ([#4812](https://redirect.github.com/webpack/webpack-cli/issues/4812)) * Additional commits viewable in [compare view](https://github.com/webpack/webpack-cli/compare/webpack-cli@7.2.1...webpack-cli@7.2.2) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
Summary
Fixes #4801. gRPC
StreamObserveris not thread-safe, butArcadeDbGrpcService.graphBatchLoadandinsertBidirectionalissued terminal/write calls (onNext/onError/onCompleted) directly on the raw observer:graphBatchLoadrelied on a TOCTOUif (!cancelled.get())check, so a cancellation racing the final terminal call could deliver a write/terminal on an already-closed call.insertBidirectionaldispatched DB work to a single-threaded executor and called terminal methods from those tasks while the cancel handler ran on the transport thread; a duplicate terminal (e.g. COMMIT then a stray message hitting the defensive catch) or a cancellation could interleave terminal calls.Symptoms:
IllegalStateException("call already closed"), dropped responses, or client hangs.Fix
New
SynchronizedStreamObserver<T>(grpcw) wraps the response observer and:AtomicBoolean completedCAS, and drops anyonNextafter a terminal call;markTerminated()for the call's cancel handler to flip the flag without delegating (the transport already closed the call);IllegalStateExceptionthe delegate throws on a concurrent close, marking itself terminated.Both streaming handlers now route all write/terminal calls through it; the original
ServerCallStreamObserverreference is kept only for flow control.Tests
Issue4801SynchronizedStreamObserverTest(unit, mock-free) drives the wrapper against a delegate that emulates gRPC's contract (throws on a second terminal / write-after-close):onNextafteronCompletedmarkTerminateddrops subsequent calls without delegatingIllegalStateExceptionon concurrent close is swallowedonNext/onCompleted/onError/markTerminated- no exception escapes, never more than one terminal, no contract violationRed/green verified: a naive pass-through wrapper fails with the exact
IllegalStateException: call already closedfrom the issue; the fix makes all 5 pass.GrpcServerIT#graphBatchLoadVerticesAndEdgesstill passes end-to-end.🤖 Generated with Claude Code