mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(core): bind the DB proxies and EC2 port forwards with a 4096 backlog (#6744)
This commit is contained in:
1 parent
de2e5192b2
commit
1356cbbc84
12 files changed
+183
-22
No files matched your search
+3
-3
@@ -242,7 +242,7 @@ class Ec2PortForwardManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void publishedForwardDisablesNagleOnBothSocatSockets() {
|
||||
void publishedForwardDisablesNagleAndBindsABurstTolerantAcceptBacklog() {
|
||||
DockerClient dockerClient = mock(DockerClient.class);
|
||||
when(dockerClient.inspectContainerCmd(anyString())).thenThrow(new RuntimeException("docker down"));
|
||||
PortAllocator portAllocator = mock(PortAllocator.class);
|
||||
@@ -274,8 +274,8 @@ class Ec2PortForwardManagerTest {
|
||||
verify(lifecycleManager).create(spec.capture());
|
||||
assertEquals("alpine/socat", spec.getValue().image());
|
||||
assertEquals(List.of("socat"), spec.getValue().entrypoint());
|
||||
assertEquals(List.of("TCP-LISTEN:80,fork,reuseaddr,nodelay", "TCP:172.17.0.3:80,nodelay"),
|
||||
spec.getValue().cmd());
|
||||
assertEquals(List.of("TCP-LISTEN:80,fork,reuseaddr,nodelay,backlog=4096",
|
||||
"TCP:172.17.0.3:80,nodelay"), spec.getValue().cmd());
|
||||
assertEquals(Map.of(80, 30000), spec.getValue().portBindings());
|
||||
}
|
||||
|
||||
|
||||
+21
-1
@@ -7,6 +7,7 @@ import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@@ -125,7 +126,26 @@ class AbstractRedisAuthProxyRelayTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class TestProxy extends AbstractRedisAuthProxy {
|
||||
@Test
|
||||
void bindsWithABurstTolerantAcceptBacklog() throws Exception {
|
||||
AtomicInteger acceptBacklog = new AtomicInteger();
|
||||
TestProxy proxy = new TestProxy("127.0.0.1", 1) {
|
||||
@Override
|
||||
ServerSocket listenSocket(int proxyPort, int backlog) throws IOException {
|
||||
acceptBacklog.set(backlog);
|
||||
return super.listenSocket(proxyPort, backlog);
|
||||
}
|
||||
};
|
||||
proxy.start(0);
|
||||
try {
|
||||
assertEquals(4096, acceptBacklog.get(),
|
||||
"a connection burst must not overflow the proxy's accept queue");
|
||||
} finally {
|
||||
proxy.stop();
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestProxy extends AbstractRedisAuthProxy {
|
||||
private TestProxy(String backendHost, int backendPort) {
|
||||
super(org.jboss.logging.Logger.getLogger(TestProxy.class), "test", "test", "relay",
|
||||
backendHost, backendPort);
|
||||
|
||||
+21
@@ -2,9 +2,11 @@ package io.github.hectorvent.floci.services.neptune.proxy;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@@ -126,4 +128,23 @@ class NeptuneGremlinProxyRelayTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindsWithABurstTolerantAcceptBacklog() throws Exception {
|
||||
AtomicInteger acceptBacklog = new AtomicInteger();
|
||||
NeptuneGremlinProxy proxy = new NeptuneGremlinProxy("cluster", "127.0.0.1", 1) {
|
||||
@Override
|
||||
ServerSocket listenSocket(int proxyPort, int backlog) throws IOException {
|
||||
acceptBacklog.set(backlog);
|
||||
return super.listenSocket(proxyPort, backlog);
|
||||
}
|
||||
};
|
||||
proxy.start(0);
|
||||
try {
|
||||
assertEquals(4096, acceptBacklog.get(),
|
||||
"a connection burst must not overflow the proxy's accept queue");
|
||||
} finally {
|
||||
proxy.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-3
@@ -18,6 +18,7 @@ import java.nio.file.Path;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -26,9 +27,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Covers the connection bounds (handshake timeout, backend-connect deferral, permit pool) added
|
||||
* to {@link RdsAuthProxy} for the POSTGRES engine, mirroring the equivalent coverage in
|
||||
* {@code RedshiftAuthProxyTest}.
|
||||
* Covers the connection bounds (handshake timeout, backend-connect deferral, permit pool,
|
||||
* accept backlog) added to {@link RdsAuthProxy} for the POSTGRES engine, mirroring the
|
||||
* equivalent coverage in {@code RedshiftAuthProxyTest}.
|
||||
*/
|
||||
class RdsAuthProxyBoundsTest {
|
||||
|
||||
@@ -146,6 +147,24 @@ class RdsAuthProxyBoundsTest {
|
||||
assertTrue(released.await(5, TimeUnit.SECONDS), "the lease is released when the connection ends");
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindsWithABurstTolerantAcceptBacklog() throws Exception {
|
||||
AtomicInteger acceptBacklog = new AtomicInteger();
|
||||
proxy = new RdsAuthProxy("db-1", "localhost", 1, "runtime:db-1",
|
||||
DatabaseEngine.POSTGRES, false, "admin", "Secret123", "dev",
|
||||
mock(RdsSigV4Validator.class), realTls(), (user, pw) -> true,
|
||||
5000, 5000, 100) {
|
||||
@Override
|
||||
ServerSocket listenSocket(int proxyPort, int backlog) throws IOException {
|
||||
acceptBacklog.set(backlog);
|
||||
return super.listenSocket(proxyPort, backlog);
|
||||
}
|
||||
};
|
||||
proxy.start(0);
|
||||
assertEquals(4096, acceptBacklog.get(),
|
||||
"a connection burst must not overflow the proxy's accept queue");
|
||||
}
|
||||
|
||||
private RdsAuthProxy newProxy(int handshakeTimeoutMillis, int backendConnectTimeoutMillis,
|
||||
int maxConnections) {
|
||||
return newProxy("runtime:db-1", handshakeTimeoutMillis, backendConnectTimeoutMillis, maxConnections);
|
||||
|
||||
+19
@@ -29,6 +29,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -306,6 +307,24 @@ class RedshiftAuthProxyTest {
|
||||
assertEquals("rotated", f.get(proxy));
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindsWithABurstTolerantAcceptBacklog() throws Exception {
|
||||
AtomicInteger acceptBacklog = new AtomicInteger();
|
||||
proxy = new RedshiftAuthProxy("111111111111:c1", "localhost", 1,
|
||||
"admin", "Secret123", "dev",
|
||||
mock(RdsSigV4Validator.class), realTls(), (user, pw) -> PasswordValidator.AuthResult.REJECT,
|
||||
mock(S3Service.class), mock(IamService.class), 5000, 5000, 100) {
|
||||
@Override
|
||||
ServerSocket listenSocket(int proxyPort, int backlog) throws IOException {
|
||||
acceptBacklog.set(backlog);
|
||||
return super.listenSocket(proxyPort, backlog);
|
||||
}
|
||||
};
|
||||
proxy.start(0);
|
||||
assertEquals(4096, acceptBacklog.get(),
|
||||
"a connection burst must not overflow the proxy's accept queue");
|
||||
}
|
||||
|
||||
private RdsProxyTlsCertificates realTls() {
|
||||
return new RdsProxyTlsCertificates(FlociCertificateAuthority.loadOrCreate(tempDir.resolve("tls")),
|
||||
new CertificateGenerator());
|
||||
|
||||
Reference in new issue
Block a user