Merge pull request #3932 from dwijnand/max-socket-length

Handle very long socket file paths on UNIX
This commit is contained in:
Dale Wijnand 2018-02-13 07:36:15 +00:00 committed by GitHub
commit 8546fc7ea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -60,9 +60,16 @@ private[sbt] object Server {
// Named pipe already has an exclusive lock.
addServerError(new Win32NamedPipeServerSocket(pipeName))
case ConnectionType.Local =>
tryClient(new UnixDomainSocket(socketfile.getAbsolutePath))
val maxSocketLength = new UnixDomainSocketLibrary.SockaddrUn().sunPath.length - 1
val path = socketfile.getAbsolutePath
if (path.length > maxSocketLength)
sys.error("socket file absolute path too long; " +
"either switch to another connection type " +
"or define a short \"SBT_GLOBAL_SERVER_DIR\" value. " +
s"Current path: ${path}")
tryClient(new UnixDomainSocket(path))
prepareSocketfile()
addServerError(new UnixDomainServerSocket(socketfile.getAbsolutePath))
addServerError(new UnixDomainServerSocket(path))
case ConnectionType.Tcp =>
tryClient(new Socket(InetAddress.getByName(host), port))
addServerError(new ServerSocket(port, 50, InetAddress.getByName(host)))

View File

@ -139,8 +139,10 @@ private[sbt] final class CommandExchange {
if (server.isEmpty && firstInstance.get) {
val portfile = s.baseDir / "project" / "target" / "active.json"
val h = Hash.halfHashString(IO.toURI(portfile).toString)
val tokenfile = BuildPaths.getGlobalBase(s) / "server" / h / "token.json"
val socketfile = BuildPaths.getGlobalBase(s) / "server" / h / "sock"
val serverDir =
sys.env get "SBT_GLOBAL_SERVER_DIR" map file getOrElse BuildPaths.getGlobalBase(s) / "server"
val tokenfile = serverDir / h / "token.json"
val socketfile = serverDir / h / "sock"
val pipeName = "sbt-server-" + h
val connection = ServerConnection(
connectionType,