{"record":{"id":"4a4b141cead83d2e","repo":"spring-projects/spring-boot","slug":"socket-is-not-connected","errorCode":null,"errorMessage":"Socket is not connected","messagePattern":"Socket is not connected","errorType":"exception","errorClass":"SocketException","httpStatus":null,"severity":"error","filePath":"buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/UnixDomainSocket.java","lineNumber":62,"sourceCode":"\t\treturn new UnixDomainSocket(path);\n\t}\n\n\tprivate final SocketAddress socketAddress;\n\n\tprivate final SocketChannel socketChannel;\n\n\tprivate UnixDomainSocket(String path) throws IOException {\n\t\tthis.socketAddress = UnixDomainSocketAddress.of(path);\n\t\tthis.socketChannel = SocketChannel.open(this.socketAddress);\n\t}\n\n\t@Override\n\tpublic InputStream getInputStream() throws IOException {\n\t\tif (isClosed()) {\n\t\t\tthrow new SocketException(\"Socket is closed\");\n\t\t}\n\t\tif (!isConnected()) {\n\t\t\tthrow new SocketException(\"Socket is not connected\");\n\t\t}\n\t\tif (isInputShutdown()) {\n\t\t\tthrow new SocketException(\"Socket input is shutdown\");\n\t\t}\n\n\t\treturn Channels.newInputStream(this.socketChannel);\n\t}\n\n\t@Override\n\tpublic OutputStream getOutputStream() throws IOException {\n\t\tif (isClosed()) {\n\t\t\tthrow new SocketException(\"Socket is closed\");\n\t\t}\n\t\tif (!isConnected()) {\n\t\t\tthrow new SocketException(\"Socket is not connected\");\n\t\t}\n\t\tif (isOutputShutdown()) {\n\t\t\tthrow new SocketException(\"Socket output is shutdown\");","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/UnixDomainSocket.java#L44-L80","documentation":"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).","triggerScenarios":"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.","commonSituations":"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).","solutions":["Always obtain the socket via UnixDomainSocket.get(path) so SocketChannel.open connects synchronously.","Verify the unix socket path exists and the daemon is listening: `ls -l <path>` and `docker info`.","Reopen the socket if the connection was lost."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Guard before obtaining a stream\nif (!socket.isConnected()) {\n    socket = UnixDomainSocket.get(path); // reopen\n}\nInputStream in = socket.getInputStream();","typeGuard":null,"tryCatchPattern":"try {\n    socket.getInputStream();\n} catch (java.net.SocketException ex) {\n    if (\"Socket is not connected\".equals(ex.getMessage())) {\n        socket = UnixDomainSocket.get(path); // reopen and retry once\n    } else throw ex;\n}","preventionTips":["Always obtain the socket via UnixDomainSocket.get(path) so SocketChannel.open connects synchronously.","Handle IOException from open() explicitly rather than proceeding with an unconnected socket.","For test doubles, ensure connect() is invoked or mock isConnected() to return true."],"tags":["docker","socket","unix-domain-socket","connection","buildpack"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}