Skip to content

Avoid path length limitations for Unix domain sockets by chdir before bind/connect #290

@RaitoBezarius

Description

@RaitoBezarius

tmp-postgres currently creates temporary PostgreSQL instances using (long) absolute paths. This can hit Unix domain socket path length limits (often 108 characters, 104 for macOS), especially in environments like Nix builds where paths are deeply nested.

This causes failures when trying to start or connect to the database. For example, socket paths like:

/nix/var/nix/builds/nix-build-........./tmp-postgres-xxxxxxxxxxxxxx/.s.PGSQL.5432

can exceed the limit and create failure during a test harness execution.

Suggested workaround

Change the working directory (chdir) to the temp data directory before starting Postgres and using socket paths. This way, relative paths (like ./socket) stay short and avoid the issue.

See how Lix did it here: https://git.lix.systems/lix-project/lix/src/commit/801567adf0ccf41114e24a6b4f182c0da1ccf503/lix/libutil/unix-domain-socket.cc#L40-L101.

This would make tmp-postgres more reliable in build-heavy environments without filesystem namespacing abilities (i.e. this doesn't happen that much on Linux because you can hide the long prefix with kernel namespaces, which macOS cannot).

Original report came from https://git.lix.systems/lix-project/lix/issues/913#issuecomment-13322.


FWIW, Lix will workaround this problem in general, but fixing it here also makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions