alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

Fix flakes in tests using `freeAddress`

Open SoloJacobs opened this issue 1 month ago • 1 comments

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

SoloJacobs avatar Nov 18 '25 16:11 SoloJacobs

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:]

TheMeier avatar Nov 18 '25 18:11 TheMeier

Ah, wow. That is definitely a problem.

SoloJacobs avatar Nov 19 '25 07:11 SoloJacobs