Skip to content

Commit 345b09c

Browse files
author
Claude Dev
committed
fix: ReleaseIO/ReleaseCPU non-blocking to prevent hang on double-release
When a test connects twice (setupRoundtripEnv + setupRoundtripEnvFromPath), both connections register wrapWithResourceMonitor Cleanups. Each Cleanup calls ReleaseIO, but only the first connection AcquireIO'd. The second ReleaseIO blocks forever on the full token bucket. Fix: non-blocking select with default — overflow releases are safely dropped.
1 parent f40db03 commit 345b09c

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

internal/testscheduler/scheduler.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,19 @@ func (s *Scheduler) AcquireCPU(ctx context.Context) error {
4646
}
4747

4848
func (s *Scheduler) ReleaseIO() {
49-
s.ioToken <- struct{}{}
49+
select {
50+
case s.ioToken <- struct{}{}:
51+
default:
52+
// Bucket full — release would overflow. Safe to drop:
53+
// the token was already returned by another path.
54+
}
5055
}
5156

5257
func (s *Scheduler) ReleaseCPU() {
53-
s.cpuToken <- struct{}{}
58+
select {
59+
case s.cpuToken <- struct{}{}:
60+
default:
61+
}
5462
}
5563

5664
func (s *Scheduler) Adjust(limits ResourceLimit) {

0 commit comments

Comments
 (0)