8000 Set socket backlog to default size of 50 · sbt/sbt@6611ccf · GitHub
[go: up one dir, main page]

Skip to content

Commit 6611ccf

Browse files
committed
Set socket backlog to default size of 50
1 parent 09e06c4 commit 6611ccf

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ jobs:
186186
shell: bash
187187
run: |
188188
# test building sbtn on Windows
189+
sbt "commandProj/testOnly xsbt.IPCSpec"
189190
sbt "-Dsbt.io.virtual=false" nativeImage
190191
# test launcher script
191192
echo build using JDK 8, test using JDK 8, on Windows

main-command/src/main/scala/xsbt/IPC.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ object IPC {
1717
private val portMin = 1025
1818
private val portMax = 65536
1919
private val loopback = InetAddress.getByName(null)
20+
private[xsbt] val socketBacklog = 50 // 50 is the default backlog size for the java.net.Socket
2021

2122
def client[T](port: Int)(f: IPC => T): T = ipc(new Socket(loopback, port))(f)
2223

@@ -34,7 +35,7 @@ object IPC {
3435

3536
def createServer(attempts: Int): ServerSocket =
3637
if (attempts > 0) {
37-
try new ServerSocket(nextPort, 1, loopback)
38+
try new ServerSocket(nextPort, socketBacklog, loopback)
3839
catch { case NonFatal(_) => createServer(attempts - 1) }
3940
} else sys.error("Could not connect to socket: maximum attempts exceeded")
4041

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* sbt
3+
* Copyright 2011 - 2018, Lightbend, Inc.
4+
* Copyright 2008 - 2010, Mark Harrah
5+
* Licensed under Apache License 2.0 (see LICENSE)
6+
*/
7+
8+
package xsbt
9+
10+
import org.scalatest.flatspec.AnyFlatSpec
11+
import org.scalatest.matchers.should.Matchers._
12+
13+
class IPCSpec extends AnyFlatSpec {
14+
"server" should "allow same number of connections as determined in socket backlog" in {
15+
noException should be thrownBy {
16+
val server = IPC.unmanagedServer
17+
(1 until IPC.socketBacklog + 1).foreach { _ =>
18+
IPC.client(server.port)(identity)
19+
}
20+
server.close()
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)
0