mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(lambda): return {"status":"OK"} ack body from runtime invocation endpoints (#1418)
* fix(lambda): return {"status":"OK"} ack body from runtime invocation endpoints
The /response, /error and /init/error Runtime API endpoints replied with
HTTP 202 and an empty body. Runtime clients that deserialize the
acknowledgement (e.g. the .NET Amazon.Lambda.RuntimeSupport client) throw
"Could not deserialize the response body" on an empty body, crashing the
runtime process after every failed invocation. Return the AWS-documented
{"status":"OK"} JSON body instead.
* test(lambda): assert Content-Type and parse ack body in runtime tests
Cover the Content-Type: application/json header introduced by sendStatusOk
and parse the acknowledgement as JSON (asserting status == OK) instead of
comparing the raw body string, so harmless formatting changes don't break
the tests.
This commit is contained in:
1 parent
d659de942b
commit
dace94fa80
2 files changed
+84
-3
No files matched your search
+15
-3
@@ -36,6 +36,11 @@ public class RuntimeApiServer {
|
||||
private static final byte[] CONTAINER_STOPPED_PAYLOAD =
|
||||
"{\"errorMessage\":\"Container stopped\",\"errorType\":\"ContainerStopped\"}".getBytes();
|
||||
|
||||
// Acknowledgement body for the /response, /error and /init/error endpoints. Some
|
||||
// runtime clients (e.g. .NET's Amazon.Lambda.RuntimeSupport) deserialize it and
|
||||
// fail on an empty body.
|
||||
private static final String STATUS_OK_BODY = "{\"status\":\"OK\"}";
|
||||
|
||||
private final Vertx vertx;
|
||||
private final int port;
|
||||
|
||||
@@ -110,7 +115,7 @@ public class RuntimeApiServer {
|
||||
InvokeResult result = new InvokeResult(200, null, payload, null, requestId);
|
||||
invocation.getResultFuture().complete(result);
|
||||
}
|
||||
ctx.response().setStatusCode(202).end();
|
||||
sendStatusOk(ctx);
|
||||
});
|
||||
|
||||
// POST /runtime/invocation/{requestId}/error — failure
|
||||
@@ -124,13 +129,13 @@ public class RuntimeApiServer {
|
||||
InvokeResult result = new InvokeResult(200, functionError, payload, null, requestId);
|
||||
invocation.getResultFuture().complete(result);
|
||||
}
|
||||
ctx.response().setStatusCode(202).end();
|
||||
sendStatusOk(ctx);
|
||||
});
|
||||
|
||||
// POST /runtime/init/error — runtime initialization failure
|
||||
router.post(INIT_ERROR_PATH).handler(ctx -> {
|
||||
LOG.warnv("Lambda runtime reported init error on port {0}", String.valueOf(port));
|
||||
ctx.response().setStatusCode(202).end();
|
||||
sendStatusOk(ctx);
|
||||
});
|
||||
|
||||
long deadline = System.currentTimeMillis() + 5000;
|
||||
@@ -237,6 +242,13 @@ public class RuntimeApiServer {
|
||||
return invocation.getResultFuture();
|
||||
}
|
||||
|
||||
private void sendStatusOk(RoutingContext ctx) {
|
||||
ctx.response()
|
||||
.setStatusCode(202)
|
||||
.putHeader("Content-Type", "application/json")
|
||||
.end(STATUS_OK_BODY);
|
||||
}
|
||||
|
||||
private void sendInvocation(RoutingContext ctx, PendingInvocation invocation) {
|
||||
inFlight.put(invocation.getRequestId(), invocation);
|
||||
|
||||
|
||||
Reference in new issue
Block a user