alertmanager
alertmanager copied to clipboard
Fix flakes in tests using `freeAddress`
This commit addresses the following error:
time=2025-11-14T16:14:59.573Z level=ERROR source=main.go:559
msg="Listen error" err="listen tcp 127.0.0.1:36357: bind: address
already in use"
freeAddress is called multiple times within one test, but also in parallel in multiple tests. freeAddress immediately releases the port despite it being used later in a test. This causes ports to errorenously to be reused.
We replace net.Listen in order to avoid calling syscall.Listen. This way the port can be reused by AM, without the kernel assuming that port can be reused by other processes specifiying port 0.
Fixes: #4742
I tried this locally and it still produces the same error but now in TestColdStart
--- FAIL: TestColdStart (5.07s)
acceptance.go:193: failed to start alertmanager cluster: unable to get a successful response from the Alertmanager: Get "http://127.0.0.1:37501/api/v2/status": dial tcp 127.0.0.1:37501: connect: connection refused
send_test.go:481:
collector "webhook":
interval [4,5]
---
- &{map[] 0001-01-01T00:00:00.000Z <nil> [] 0001-01-01T00:00:01.000Z <nil> <nil> { map[alertname:test1]}}[1:]
Ah, wow. That is definitely a problem.