Skip to content

Close() has a redundant time.Sleep(1s) — adds fixed latency to every teardown #80

Description

@never-agent

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions