Skip to content

Commit 1e592c4

Browse files
Merge pull request #9553 from oztimpower/ext/aws-lambda-8964
Amazon Lambda Test Framework - Improved error handling for shutdown
2 parents 1036a39 + 4e2502b commit 1e592c4

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AbstractLambdaPollLoop.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,20 @@ public void run() {
5454
URL url = AmazonLambdaApi.invocationResponse(requestId);
5555
if (isStream()) {
5656
HttpURLConnection responseConnection = responseStream(url);
57-
processRequest(requestConnection.getInputStream(), responseConnection.getOutputStream(),
58-
createContext(requestConnection));
59-
while (responseConnection.getInputStream().read() != -1) {
60-
// Read data
57+
if (running.get()) {
58+
processRequest(requestConnection.getInputStream(), responseConnection.getOutputStream(),
59+
createContext(requestConnection));
60+
while (responseConnection.getInputStream().read() != -1) {
61+
// Read data
62+
}
6163
}
6264
} else {
6365
Object input = null;
64-
if (getInputReader() != null)
66+
if (running.get() && getInputReader() != null) {
6567
input = getInputReader().readValue(requestConnection.getInputStream());
66-
Object output = processRequest(input, createContext(requestConnection));
67-
postResponse(url, output);
68+
Object output = processRequest(input, createContext(requestConnection));
69+
postResponse(url, output);
70+
}
6871
}
6972
} catch (Exception e) {
7073
log.error("Failed to run lambda", e);
@@ -82,7 +85,10 @@ public void run() {
8285
}
8386
return;
8487
} finally {
85-
requestConnection.getInputStream().close();
88+
try {
89+
requestConnection.getInputStream().close();
90+
} catch (IOException e) {
91+
}
8692
}
8793

8894
}

test-framework/amazon-lambda/src/main/java/io/quarkus/amazon/lambda/test/LambdaResourceManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
3636
Map.Entry<String, String> req = null;
3737
while (req == null) {
3838
req = LambdaClient.REQUEST_QUEUE.poll(100, TimeUnit.MILLISECONDS);
39-
if (undertow == null || undertow.getWorker().isShutdown()) {
39+
if (undertow == null || undertow.getWorker() == null || undertow.getWorker().isShutdown()) {
4040
return;
4141
}
4242
}

0 commit comments

Comments
 (0)