Repository navigation
fix(adkrest): treat MaxConcurrentRuns<=0 as unlimited in the Eventarc trigger - #2191
Conversation
… 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.
|
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 this is a small doc or typo fix, ignore me. A maintainer can open the issue for you if you would rather. |
wolo-lab
left a comment
There was a problem hiding this comment.
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<=0must mean no limit, but the test only sets 0 (eventarc_test.go#L243-L251). This change also fixes negative values: on main,MaxConcurrentRuns: -1panics insideNewEventarcControllerWithConfigwithmakechan: size out of range, and with this PR it does not. Nothing pins that. Changing> 0to!= 0in 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_ZeroMaxConcurrentRunsIsUnlimitedwould 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: 1silently 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.
|
Both must-change items plus the non-blocking suggestions are in 3b53b1d:
|
…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)
Problem
NewEventarcControllerWithConfigbuilds its semaphore unconditionally:With the natural "no limit" value
0, that's an unbuffered channel — not nil — so the handler'sif c.semaphore != nilguard passes, the send at the top ofEventarcTriggerHandlerhas no receiver (the matching receive lives in adeferthat never runs), and every Eventarc request blocks forever.The sibling
PubSubControlleralready 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 releasedNewEventarcController/NewEventarcControllerWithConfigAPI 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.