Skip to content

Commit bf30712

Browse files
fix(event_handler): avoid deadlock in async resolver
1 parent 835d0fd commit bf30712

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

tests/functional/event_handler/required_dependencies/test_async_middleware_frame.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Response,
1010
)
1111
from aws_lambda_powertools.event_handler.middlewares import NextMiddleware
12-
from aws_lambda_powertools.event_handler.middlewares.async_utils import AsyncMiddlewareFrame
12+
from aws_lambda_powertools.event_handler.middlewares.async_utils import AsyncMiddlewareFrame, wrap_middleware_async
1313
from tests.functional.utils import load_event
1414

1515
API_REST_EVENT = load_event("apiGatewayProxyEvent.json")
@@ -45,6 +45,28 @@ async def next_handler(app: ApiGatewayResolver):
4545
asyncio.run(frame(app))
4646

4747

48+
def test_wrap_middleware_async_sync_raising_before_next_does_not_deadlock():
49+
# GIVEN a sync middleware that raises before calling next(), using wrap_middleware_async
50+
# This exercises _run_sync_middleware_in_thread directly
51+
app = _make_app()
52+
53+
class AuthError(Exception):
54+
pass
55+
56+
def failing_middleware(app, next_middleware):
57+
raise AuthError("denied")
58+
59+
async def next_handler(app):
60+
return Response(200, content_types.TEXT_HTML, "should not reach")
61+
62+
wrapped = wrap_middleware_async(failing_middleware, next_handler)
63+
64+
# WHEN calling the wrapped middleware
65+
# THEN the exception propagates without deadlocking
66+
with pytest.raises(AuthError, match="denied"):
67+
asyncio.run(wrapped(app))
68+
69+
4870
def test_async_middleware_raising_before_next_propagates():
4971
# GIVEN an async middleware that raises before calling next()
5072
app = _make_app()

0 commit comments

Comments
 (0)