Merge pull request #7087 from mdedetrich/increase-socket-backlog-for-server-client

Set socket backlog to default size of 50
This commit is contained in:
eugene yokota 2023-09-13 11:07:44 -04:00 committed by GitHub
commit f7025eff6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

@ -186,6 +186,7 @@ jobs:
shell: bash
run: |
# test building sbtn on Windows
sbt "commandProj/testOnly xsbt.IPCSpec"
sbt "-Dsbt.io.virtual=false" nativeImage
# test launcher script
echo build using JDK 8, test using JDK 8, on Windows

View File

@ -18,6 +18,7 @@ object IPC {
private val portMin = 1025
private val portMax = 65536
private val loopback = InetAddress.getByName(null)
private[xsbt] val socketBacklog = 50 // 50 is the default backlog size for the java.net.Socket
def client[T](port: Int)(f: IPC => T): T = ipc(new Socket(loopback, port))(f)
@ -35,7 +36,7 @@ object IPC {
def createServer(attempts: Int): ServerSocket =
if (attempts > 0) {
try new ServerSocket(nextPort, 1, loopback)
try new ServerSocket(nextPort, socketBacklog, loopback)
catch { case NonFatal(_) => createServer(attempts - 1) }
} else sys.error("Could not connect to socket: maximum attempts exceeded")

View File

@ -0,0 +1,23 @@
/*
* sbt
* Copyright 2011 - 2018, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package xsbt
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers._
class IPCSpec extends AnyFlatSpec {
"server" should "allow same number of connections as determined in socket backlog" in {
noException should be thrownBy {
val server = IPC.unmanagedServer
(1 until IPC.socketBacklog + 1).foreach { _ =>
IPC.client(server.port)(identity)
}
server.close()
}
}
}