dskit icon indicating copy to clipboard operation
dskit copied to clipboard

Lots of tests listen on 0.0.0.0

Open kevinburkesegment opened this issue 2 years ago • 4 comments

Many of the tests in the test suite attempt to bind to a random port on 0.0.0.0, which means anything can make a connection to the server, including external devices.

On Mac, this is very annoying because each invocation triggers a dialog box asking to allow connections to the test binary. I counted about ten or so of these dialog boxes in one run of the test suite.

To track down this issue, edit $GOROOT/src/net/dial.go, and add the following patch to ListenConfig.Listen:

 // See func Listen for a description of the network and address
 // parameters.
 func (lc *ListenConfig) Listen(ctx context.Context, network, address string) (Listener, error) {
+	if address == ":0" {
+		fmt.Println("ListenConfig.Listen", network, address)
+		debug.PrintStack()
+	}
 	addrs, err := DefaultResolver.resolveAddrList(ctx, "listen", network, address, nil)

Then rerun the tests. This will likely show you which test file is responsible for opening a socket to 0.0.0.0.

kevinburkesegment avatar Sep 15 '23 22:09 kevinburkesegment

Would listening on 127.0.0.1 instead of 0.0.0.0 fix the issue?

pracucci avatar Sep 18 '23 05:09 pracucci

Yes - here's an example CL submitting a patch: https://github.com/grafana/loki/pull/10411

Some machines map "localhost" to a different IP than 127.0.0.1 but it's sufficient for most machines to dial this host.

kevinburkesegment avatar Sep 19 '23 14:09 kevinburkesegment

Basically - I'm happy to fix these just wanted some guidance that this is something you'd be interested in reviewing and merging.

kevinburkesegment avatar Sep 25 '23 18:09 kevinburkesegment

Yep, please do open a PR :+1:

aknuds1 avatar Sep 26 '23 06:09 aknuds1