Skip to content

Remove startAsync() to prevent void methods from hanging forever#1600

Open
kosmakdm wants to merge 1 commit intoaws:mainfrom
kosmakdm:fix/1598
Open

Remove startAsync() to prevent void methods from hanging forever#1600
kosmakdm wants to merge 1 commit intoaws:mainfrom
kosmakdm:fix/1598

Conversation

@kosmakdm
Copy link

@kosmakdm kosmakdm commented Mar 3, 2026

Issue #, if available: #1598

Description of changes:

Root Cause

The springboot4 module unconditionally calls httpServletRequest.startAsync() before delegating to AwsSpringHttpProcessingUtils.processRequest(). This call present in both SpringDelegatingLambdaContainerHandler.handleRequest() and AwsSpringWebCustomRuntimeEventLoop.eventLoop(), it sets the request's dispatcher type to DispatcherType.ASYNC.

After ServerlessMVC.service() processes the request and the servlet/filter chain completes, there is a safety-net flush that ensures the response is always committed:

if (!response.isCommitted() && request.getDispatcherType() != DispatcherType.ASYNC) {
    response.flushBuffer();
}

Because startAsync() forces the dispatcher type to ASYNC, this safety net is skipped. For controllers that return a response body, this doesn't matter - Spring's HttpMessageConverter flushes the output stream during body serialization, which triggers AwsHttpServletResponse.flushBuffer() -> writersCountDownLatch.countDown(). But for void-returning controllers (e.g. a POST that creates a resource and returns nothing), no message converter runs, no flush ever happens, countDown() is never called, and latch.await(15, TimeUnit.MINUTES) blocks indefinitely.

The springboot3 module does NOT call startAsync(), so the safety-net flush always executes and the latch always counts down - even for void-returning controllers. This is why the same controller code works with Spring Boot 3 but hangs with Spring Boot 4.

Fix

Remove the unconditional httpServletRequest.startAsync() calls from both SpringDelegatingLambdaContainerHandler and AwsSpringWebCustomRuntimeEventLoop, aligning the springboot4 behavior with springboot3.

Changes

  • SpringDelegatingLambdaContainerHandler.java: Removed httpServletRequest.startAsync() call
  • AwsSpringWebCustomRuntimeEventLoop.java: Removed httpServletRequest.startAsync() call
  • SpringDelegatingLambdaContainerHandlerTests.java: Added voidPost_returns200 test that verifies void-returning POST controllers complete successfully
  • ServletApplication.java: Added voidPost() endpoint for the new test

By submitting this pull request

  • I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • I confirm that I've made a best effort attempt to update all relevant documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant