spring-projects/spring-boot · error · SocketException

Socket is not connected

Error message

Socket is not connected

What it means

After the isClosed() check, UnixDomainSocket.getInputStream/getOutputStream check isConnected() and throw SocketException('Socket is not connected') if false. For a socket built via the public UnixDomainSocket.get(path), the constructor calls SocketChannel.open(socketAddress) which connects synchronously, so under normal use this branch fires only when the channel never reached the connected state (test doubles, a channel that connected then was reset before use, or a subclass that bypassed the factory).

Source

Thrown at buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/UnixDomainSocket.java:62

		return new UnixDomainSocket(path);
	}

	private final SocketAddress socketAddress;

	private final SocketChannel socketChannel;

	private UnixDomainSocket(String path) throws IOException {
		this.socketAddress = UnixDomainSocketAddress.of(path);
		this.socketChannel = SocketChannel.open(this.socketAddress);
	}

	@Override
	public InputStream getInputStream() throws IOException {
		if (isClosed()) {
			throw new SocketException("Socket is closed");
		}
		if (!isConnected()) {
			throw new SocketException("Socket is not connected");
		}
		if (isInputShutdown()) {
			throw new SocketException("Socket input is shutdown");
		}

		return Channels.newInputStream(this.socketChannel);
	}

	@Override
	public OutputStream getOutputStream() throws IOException {
		if (isClosed()) {
			throw new SocketException("Socket is closed");
		}
		if (!isConnected()) {
			throw new SocketException("Socket is not connected");
		}
		if (isOutputShutdown()) {
			throw new SocketException("Socket output is shutdown");

View on GitHub (pinned to 270dfe353f)

Solutions

  1. Always obtain the socket via UnixDomainSocket.get(path) so SocketChannel.open connects synchronously.
  2. Verify the unix socket path exists and the daemon is listening: `ls -l <path>` and `docker info`.
  3. Reopen the socket if the connection was lost.
Defensive patterns

Strategy: validation

Validate before calling

// Guard before obtaining a stream
if (!socket.isConnected()) {
    socket = UnixDomainSocket.get(path); // reopen
}
InputStream in = socket.getInputStream();

Try / catch

try {
    socket.getInputStream();
} catch (java.net.SocketException ex) {
    if ("Socket is not connected".equals(ex.getMessage())) {
        socket = UnixDomainSocket.get(path); // reopen and retry once
    } else throw ex;
}

Prevention

When it happens

Trigger: getInputStream()/getOutputStream() called when isConnected() returns false: the SocketChannel is not in a connected state. Possible if the open() connect failed but did not throw, the channel was reset, or a test double extends the socket without connecting.

Common situations: A mock/test subclass of AbstractSocket that never connected; a channel whose connection was reset between construction and use; misuse where a raw AbstractSocket is constructed without going through UnixDomainSocket.get(path).

Related errors


AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11). Data as JSON: /api/errors/4a4b141cead83d2e. Report an issue: GitHub.