#401·ants

TestAntsPool hangs when the package is run with -count>1

Author: rowhitswamiCreated Sep 8, 2026Updated Sep 8, 2026
Labelshelp wantedneeds investigationneeds more info

TestAntsPool blocks indefinitely when the test binary runs it more than once in the same process, so go test -count=2 or higher never completes and the whole package times out.

Reproduction

$ git clone https://github.com/panjf2000/ants && cd ants
$ go test -run 'TestAntsPool$' -count=2 .
panic: test timed out after 10m0s
	running tests:
		TestAntsPool (7m40s)

-count=1 is unaffected.

What I measured

Thirty-five isolated attempts at 107e3767, each a fresh process, with -shuffle on and a four-minute ceiling:

passed hung
-count=1 15 0
-count=2 0 5
-count=3 0 15

Deterministic — a single extra iteration is enough.

Goroutine state at the timeout

testing.(*T).Run is waiting, while janitor goroutines from several pool instances are still live:

goroutine 1 [chan receive, 7 minutes]:
testing.(*T).Run(...)

goroutine 246 [select]:
github.com/panjf2000/ants/v2.(*poolCommon).purgeStaleWorkers(0x140000a8780)
	ants.go:261
created by github.com/panjf2000/ants/v2.(*poolCommon).goPurge

goroutine 247 [select]:
github.com/panjf2000/ants/v2.(*poolCommon).ticktock(0x140000a8780)
	ants.go:304
created by github.com/panjf2000/ants/v2.(*poolCommon).goTicktock

I have not diagnosed the root cause and I am not claiming a deadlock in the pool itself — the blocking may well be in the test rather than the library.

Why it might be worth fixing

go test -count=N is the usual way to surface flaky tests, and -count with -shuffle is what catches failures that depend on ordering or on state left behind by earlier tests. At present that technique cannot be used on this package at all.

Disclosure

I found this while testing flakestat, a flaky-test detector I wrote, against real Go projects. ants was picked because it is actively maintained and concurrency-heavy, not because I suspected anything. Happy to run further experiments if any would help; I did not open a PR because I do not know whether the right fix belongs in the test or the pool.

Environment: go1.25.4, darwin/arm64, commit 107e37678122b00e1b365636ce4f80623ba41579.