Skip to content

Commit 96bc2f5

Browse files
committed
Added latch countdown on exception to address a potential leak in the implementation of #273
1 parent ea3fb4b commit 96bc2f5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/LambdaContainerHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ public void setLogFormatter(LogFormatter<ContainerRequestType, ContainerResponse
195195
*/
196196
public ResponseType proxy(RequestType request, Context context) {
197197
lambdaContext = context;
198+
CountDownLatch latch = new CountDownLatch(1);
198199
try {
199200
SecurityContext securityContext = securityContextWriter.writeSecurityContext(request, context);
200-
CountDownLatch latch = new CountDownLatch(1);
201201
ContainerRequestType containerRequest = requestReader.readRequest(request, securityContext, context, config);
202202
ContainerResponseType containerResponse = getContainerResponse(containerRequest, latch);
203203

@@ -219,6 +219,9 @@ public ResponseType proxy(RequestType request, Context context) {
219219
return responseWriter.writeResponse(containerResponse, context);
220220
} catch (Exception e) {
221221
log.error("Error while handling request", e);
222+
// release all waiting threads. This is safe here because if the count was already 0
223+
// the latch will do nothing
224+
latch.countDown();
222225

223226
return exceptionHandler.handle(e);
224227
}

0 commit comments

Comments
 (0)