Skip to content

fix(adkrest): treat MaxConcurrentRuns<=0 as unlimited in the Eventarc trigger - #2191

Merged
wolo-lab merged 3 commits into
google:mainfrom
PratikDhanave:fix/eventarc-zero-maxconcurrent
Nov 9, 2026
Merged

wolo-lab merged 3 commits into
google:mainfrom
PratikDhanave:fix/eventarc-zero-maxconcurrent

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

Problem

NewEventarcControllerWithConfig builds its semaphore unconditionally:

semaphore: make(chan struct{}, cfg.TriggerConfig.MaxConcurrentRuns),

With the natural "no limit" value 0, that's an unbuffered channel — not nil — so the handler's if c.semaphore != nil guard passes, the send at the top of EventarcTriggerHandler has no receiver (the matching receive lives in a defer that never runs), and every Eventarc request blocks forever.

The sibling PubSubController already handles exactly this ("make(chan, 0) would be an unbuffered channel (not nil), which would make every request block forever" — its own comment) and has a dedicated regression test (TestPubSubTriggerHandler_ZeroMaxConcurrentRunsIsUnlimited). Eventarc missed both.

The in-repo web launcher rejects triggerMaxRuns <= 0, so the shipped binary is safe; any direct consumer of the released NewEventarcController / NewEventarcControllerWithConfig API that mirrors Pub/Sub's documented 0-means-unlimited contract deadlocks.

Change

Copy the Pub/Sub pattern (nil semaphore for non-positive values) and mirror its regression test as TestEventarcTriggerHandler_ZeroMaxConcurrentRunsIsUnlimited. Before the fix the new test hangs and fails its 2-second guard; after it, the handler completes with 200.

Verification

  • go test ./server/adkrest/controllers/triggers/ -count=1 — full package passes.
  • golangci-lint run ./server/adkrest/controllers/triggers/... — 0 issues.

… trigger

NewEventarcControllerWithConfig built its semaphore with
make(chan struct{}, cfg.TriggerConfig.MaxConcurrentRuns) unconditionally.
With the natural "no limit" value 0 that is an unbuffered channel - not
nil - so the handler's non-nil guard passes, the send at the top of
EventarcTriggerHandler has no receiver (the matching receive is in a
defer that never runs), and every Eventarc request blocks forever.

The sibling Pub/Sub controller already leaves the semaphore nil for
non-positive values and documents exactly this trap, with a dedicated
regression test. Copy that pattern and its test to Eventarc; the test
hangs (and fails on its 2s guard) before the fix.

The in-repo web launcher rejects triggerMaxRuns <= 0, so the shipped
binary was safe; any direct consumer of the released
NewEventarcController API mirroring Pub/Sub's documented 0-means-
unlimited contract deadlocked.
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

Thanks for the PR, @PratikDhanave.

One thing before review. Our contribution guide asks for an issue behind each change, and I could not find one linked here.

  • If an issue already exists, add Closes: #<number> or Related: #<number> to the description.
  • If not, open one — the link prefills the bug template with your PR title — then reference it the same way.

If this is a small doc or typo fix, ignore me. A maintainer can open the issue for you if you would rather.

@wolo-lab wolo-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two gaps in the new test need closing before merge. The fix itself is correct and matches what the Pub/Sub controller already does.

Must change before merge:

  • Cover a negative value. The test comment says MaxConcurrentRuns<=0 must mean no limit, but the test only sets 0 (eventarc_test.go#L243-L251). This change also fixes negative values: on main, MaxConcurrentRuns: -1 panics inside NewEventarcControllerWithConfig with makechan: size out of range, and with this PR it does not. Nothing pins that. Changing > 0 to != 0 in the condition (eventarc.go#L76) brings the panic back, and every test that can reach this package still passes.
  • Show that zero means unlimited, not just unblocked. The test sends a single request, so it cannot tell "no limit" apart from a small cap (eventarc_test.go#L274-L287). If the non-positive branch built make(chan struct{}, 1) instead of leaving the semaphore nil, TestEventarcTriggerHandler_ZeroMaxConcurrentRunsIsUnlimited would still pass. The test needs to observe more than one request in flight at the same time.

The property both cases protect: a value of zero or below never blocks, panics or caps a request, and a positive N caps concurrent runs at exactly N.

Non-blocking:

  • Eventarc has no test showing that a positive limit actually limits. Pub/Sub has one (pubsub_test.go#L340), and the Eventarc gap predates this PR. This PR does rewrite the line such a test would protect, though: with the condition at eventarc.go#L76 changed to > 1, MaxConcurrentRuns: 1 silently becomes unlimited and the suite stays green. Worth adding here if it is convenient.
  • The godoc on TriggerConfig.MaxConcurrentRuns (config.go#L27) still does not say that zero or below means no limit. That was already true for Pub/Sub, so it can be a follow-up.

…ally

Review follow-up. The unlimited test now covers MaxConcurrentRuns of 0
and -1 (the negative value panicked the constructor on main) and fires
three concurrent requests at a blocking agent, requiring all three in
flight at once — so it distinguishes no-limit from any small cap and
asserts every request completed with 200. Add the positive-limit
sibling of the Pub/Sub test: N+1 requests against MaxConcurrentRuns=N
leave exactly N running. Document that zero or below means no limit on
TriggerConfig.MaxConcurrentRuns.
@PratikDhanave

Copy link
Copy Markdown
Contributor Author

Both must-change items plus the non-blocking suggestions are in 3b53b1d:

  • Negative value covered: the unlimited test is now a table over MaxConcurrentRuns ∈ {0, -1} — the -1 subtest pins the makechan: size out of range constructor panic you found on main.
  • Zero provably means unlimited: it now fires three concurrent requests at a blocking agent and requires all three in flight simultaneously before releasing, so a make(chan struct{}, 1) (or any small cap) fails it. Each request is also asserted to complete with 200, which subsumes the runCount check.
  • Positive limit enforced (your > 1 mutation): added TestEventarcTriggerHandler_EnforcesMaxConcurrentRuns, a direct mirror of the Pub/Sub test — N+1 requests against N leave exactly N running, the extra one blocked on the semaphore.
  • Godoc: TriggerConfig.MaxConcurrentRuns now states zero-or-below means no limit.

go test ./server/adkrest/controllers/triggers/ -race and golangci-lint both clean.

@wolo-lab wolo-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@wolo-lab
wolo-lab merged commit 2278f8f into google:main Nov 9, 2026
15 checks passed
wolo-lab added a commit that referenced this pull request Nov 16, 2026
…1720, #2106, #2090, #1870, #1988, #2052, #2107, #2199, #2191, #2192) (#2358)

* fix(server/triggers): honor MaxConcurrentRuns in PubSubController (#1720)

(cherry picked from commit 26495ae)

* fix(adkrest): let AutoCreateSession reach /run and /run_sse (#2106)

(cherry picked from commit f6da03a)

* fix(adkrest): answer [] from /run when a run yields no events (#2090)

(cherry picked from commit 0159a2e)

* fix(adkrest): include timestamp in REST Event model (#1870)

(cherry picked from commit 4db0bd9)

* fix(adkrest): preserve debug span attribute types (#1988)

(cherry picked from commit c377836)

* fix(triggers): use timer-and-select for context-aware retry backoff (#2052)

(cherry picked from commit 123fea9)

* fix(adkrest): answer 500, not 404, when /run cannot read the session (#2107)

(cherry picked from commit 8ce8f01)

* fix(agentengine): preserve fractional seconds in event timestamp encoding (#2199)

(cherry picked from commit c00807e)

* fix(adkrest): treat MaxConcurrentRuns<=0 as unlimited in the Eventarc trigger (#2191)

(cherry picked from commit 2278f8f)

* fix(adkrest): drop nil parts when serializing events and scanning the event graph  (#2192)

(cherry picked from commit 3193128)
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.

2 participants