Summary
Close() ends with time.Sleep(time.Second) to "wait for process to fully terminate", but Stop() already calls a.cmd.Wait(), which blocks until the process is reaped. The sleep is redundant and adds a fixed 1s to every teardown.
Detail
anvil.go (Close):
if stopErr := a.Stop(); stopErr != nil { ... }
// Wait for process to fully terminate
time.Sleep(time.Second)
Stop() already does _ = a.cmd.Wait() after Process.Kill(), which is the real synchronization point — by the time Stop() returns, the process is reaped. The trailing sleep therefore adds 1s of pure wall-clock to every Close(). Across a suite that spins instances up and down (or even the shared-anvil teardown), that is measurable dead time.
Suggested fix
Remove the time.Sleep. If there's a residual concern about port release before the next instance binds the same port, poll the port for closure (bounded) rather than sleeping a fixed second.
Confidence
High — read directly from source. Wait() semantics are well-defined; the sleep adds no synchronization Wait() doesn't already provide.
Found during an external read-through of go-anvil@3701910. Not covered by any open v0.2.0 issue.
Summary
Close()ends withtime.Sleep(time.Second)to "wait for process to fully terminate", butStop()already callsa.cmd.Wait(), which blocks until the process is reaped. The sleep is redundant and adds a fixed 1s to every teardown.Detail
anvil.go(Close):Stop()already does_ = a.cmd.Wait()afterProcess.Kill(), which is the real synchronization point — by the timeStop()returns, the process is reaped. The trailing sleep therefore adds 1s of pure wall-clock to everyClose(). Across a suite that spins instances up and down (or even the shared-anvil teardown), that is measurable dead time.Suggested fix
Remove the
time.Sleep. If there's a residual concern about port release before the next instance binds the same port, poll the port for closure (bounded) rather than sleeping a fixed second.Confidence
High — read directly from source.
Wait()semantics are well-defined; the sleep adds no synchronizationWait()doesn't already provide.Found during an external read-through of
go-anvil@3701910. Not covered by any open v0.2.0 issue.