mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lambdaweb): never run a request twice when the app crashes (#5842)
* fix(lambdaweb): retry a failed request only when Floci saw the exit before sending it A request that found its environment dead was retried when Docker's exit time came before the request start. Docker takes that time from the daemon's clock, which can be seconds behind Floci's. So a request the app had received could run a second time. Docker also reports an exit late under load. Until then the dead environment stayed in the pool, and the next request got a 503 too. Floci now follows each environment with an attach stream. The stream ends when the process exits, and Floci notes the time on its own clock. A failed request waits for that, up to one second. It is retried only if the exit came before it was sent. Otherwise it gets the 503 page after the dead environment has left the pool. * docs(lambdaweb): note the short window after an exit in the 503 row * fix(lambdaweb): clean up an exited environment off the reaper thread Docker can take seconds to report an exit status under load. On the reaper this held up the rearm of dropped exit watches and the idle checks. * test(lambdaweb): wait for Floci to see the exit instead of polling for the container
This commit is contained in:
1 parent
7cab804d22
commit
c8de16ffc7
5 files changed
+143
-48
No files matched your search
+19
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.lambdaweb;
|
||||
|
||||
import com.github.dockerjava.api.DockerClient;
|
||||
import io.github.hectorvent.floci.services.lambdaweb.LambdaWebEnvironmentManager.Environment;
|
||||
import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
@@ -18,6 +19,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -74,6 +76,7 @@ class LambdaWebDataPlaneDockerIntegrationTest {
|
||||
res.writeHead(Number(req.url.split('/')[2]), {'x-app': 'yes'}); res.end('status body'); return;
|
||||
}
|
||||
if (req.url.startsWith('/crash')) { setTimeout(() => process.exit(1), 50); return; }
|
||||
if (req.url.startsWith('/exit')) { res.end('bye', () => process.exit(0)); return; }
|
||||
let body = '';
|
||||
req.on('data', (chunk) => { body += chunk; });
|
||||
req.on('end', () => {
|
||||
@@ -192,6 +195,22 @@ class LambdaWebDataPlaneDockerIntegrationTest {
|
||||
assertNotEquals(logStream, after.header("lambda-web-logstream"), "a new environment serves the next request");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(180)
|
||||
void anEnvironmentThatExitsBetweenRequestsIsReplacedUnseen() throws Exception {
|
||||
String domain = createFunction(30);
|
||||
String logStream = given().header("Host", domain).when().get("/status/200")
|
||||
.then().statusCode(200).extract().header("lambda-web-logstream");
|
||||
Environment environment = environments.environmentOf(logStream);
|
||||
|
||||
given().header("Host", domain).when().get("/exit").then().statusCode(200).body(equalTo("bye"));
|
||||
environment.awaitExit(Duration.ofSeconds(30)).get();
|
||||
assertTrue(environment.exitedBefore(System.nanoTime()), "Floci did not see the environment exit");
|
||||
|
||||
given().header("Host", domain).when().get("/status/200")
|
||||
.then().statusCode(200).header("lambda-web-logstream", not(equalTo(logStream)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(240)
|
||||
void environmentsScaleUpToMaxEnvironmentsAndTheRateLimitThrottles() throws Exception {
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package io.github.hectorvent.floci.services.lambdaweb;
|
||||
|
||||
import io.github.hectorvent.floci.services.lambdaweb.LambdaWebEnvironmentManager.Environment;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class LambdaWebEnvironmentManagerTest {
|
||||
|
||||
@Test
|
||||
void onlyAnExitSeenBeforeTheRequestStartedAllowsARetry() {
|
||||
Environment environment = new Environment("pool", "rev-1", "000000000000");
|
||||
long started = System.nanoTime();
|
||||
assertFalse(environment.exitedBefore(started));
|
||||
|
||||
environment.sawExit(started);
|
||||
|
||||
assertFalse(environment.exitedBefore(started));
|
||||
assertFalse(environment.exitedBefore(started - 1));
|
||||
assertTrue(environment.exitedBefore(started + 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void awaitExitEndsWhenTheExitIsSeen() throws Exception {
|
||||
Environment environment = new Environment("pool", "rev-1", "000000000000");
|
||||
CompletableFuture<Void> waited = environment.awaitExit(Duration.ofMinutes(1));
|
||||
assertFalse(waited.isDone());
|
||||
|
||||
environment.sawExit(System.nanoTime());
|
||||
|
||||
waited.get(5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void awaitExitGivesUpOnAProcessThatKeepsRunning() throws Exception {
|
||||
Environment environment = new Environment("pool", "rev-1", "000000000000");
|
||||
|
||||
environment.awaitExit(Duration.ofMillis(10)).get(5, TimeUnit.SECONDS);
|
||||
|
||||
assertFalse(environment.exitedBefore(System.nanoTime()));
|
||||
environment.sawExit(System.nanoTime());
|
||||
assertTrue(environment.exitedBefore(System.nanoTime()));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user