Skip to content

testing: TB.TempDir paths can be too long for Unix socket paths #62614

@bradfitz

Description

@bradfitz

What version of Go are you using (go version)?

Go 1.21
darwin/arm64

What did you do?

I renamed a test to make it more descriptive (longer) and then my test failed:

    integration_test.go:879: sockFile path "/var/folders/0f/7sz95dc94nj46b6yz8p_fqd40000gn/T/TestIncrementalMapUpdatePeersRemoved1080118162/001/tailscale.sock" (len 114) is too long, must be < 104

Turns out darwin, openbsd, and freebsd at least limit the length of a unix socket to 104 bytes.

Because os.TempDir on darwin is a long user-specific thing (e.g. /var/folders/0f/7sz95dc94nj46b6yz8p_fqd40000gn/) and testing.TB.TempDir includes the test name and some suffix (TestIncrementalMapUpdatePeersRemoved1080118162), by the time those are all concatenated, you're out of space for a unix socket filename that fits in 104 bytes.

Apparently @josharian discovered this two years ago in tailscale/tailscale@f80193f where I approved a rename to make test names shorter but it didn't cross my mind to file this bug until I just hit it again now.

I ended up working around it by:

	dir := t.TempDir()
	sockFile := filepath.Join(dir, "tailscale.sock")
	if len(sockFile) >= 104 {
		// Maximum length for a unix socket on darwin. Try something else.
		sockFile = filepath.Join(os.TempDir(), rands.HexString(8)+".sock")
		t.Cleanup(func() { os.Remove(sockFile) })
	}

But that's a little gross.

What did you expect to see?

Operating systems to be less annoying. Failing that, maybe the testing package could help work around it somehow?

What did you see instead?

Failure to make a unix socket in a test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Unfortunate

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions