mono/mono · warning

attach: failed to bind IPC socket '%s': %s

Error message

attach: failed to bind IPC socket '%s': %s

What it means

After building the UNIX socket path /tmp/mono-<user>/.mono-<pid>, ipc_connect calls bind(); on failure it prints the path and strerror(errno), closes the socket fd, and returns (does not exit). The IPC listener is not established.

Source

Thrown at mono/metadata/attach.c:424

			}
		} else {
			perror ("attach: mkdir () failed");
			return;
		}
	}

	filename = g_strdup_printf ("%s/.mono-%" PRIdMAX, directory, (intmax_t) getpid ());
	unlink (filename);

	/* Bind a name to the socket.   */
	name.sun_family = AF_UNIX;
	strcpy (name.sun_path, filename);

	size = (offsetof (struct sockaddr_un, sun_path)
			+ strlen (name.sun_path) + 1);

	if (bind (sock, (struct sockaddr *) &name, size) < 0) {
		fprintf (stderr, "attach: failed to bind IPC socket '%s': %s\n", filename, strerror (errno));
		close (sock);
		return;
	}

	/* Set permissions */
	res = chmod (filename, S_IRUSR | S_IWUSR);
	if (res != 0) {
		perror ("attach: failed to set permissions on IPC socket");
		close (sock);
		unlink (filename);
		return;
	}

	res = listen (sock, 16);
	if (res != 0) {
		fprintf (stderr, "attach: listen () failed: %s\n", strerror (errno));
		exit (1);
	}

View on GitHub (pinned to 0f53e9e151)

Solutions

  1. Remove any stale socket file at the reported path: `rm <path>`.
  2. If the path is too long (long username/PID), shorten the user name or use a shorter TMP base if configurable.
  3. Check errno text: EADDRINUSE (path taken), ENAMETOOLONG (sun_path limit), EACCES (perms).
  4. Confirm /tmp supports UNIX sockets (not a strange FUSE/no-dev mount).
Defensive patterns

Strategy: validation

Validate before calling

// Pre-clean stale socket files and check path length:
//   sock="/tmp/mono-$USER/.mono-$$"
//   [ -e "$sock" ] && rm -f "$sock"
//   [ ${#sock} -ge 108 ] && echo "socket path too long; shorten username" && exit 1

Prevention

When it happens

Trigger: bind() fails: pathname too long for sun_path, another process holds the path, the path resides on a filesystem that does not support sockets, or EDQUOT/ENOSPC.

Common situations: Very long username inflating the path beyond sun_path limit; a stale socket file not removed; bind into /tmp mounted noexec/nosocket; quota exhaustion.

Related errors


AI-assisted analysis of mono/mono@0f53e9e151 (2026-08-13). Data as JSON: /api/errors/f2c6d45016cf62dd. Report an issue: GitHub.