Skip to content

fix: apply timeout to mounted ASGI apps (#5246)#5621

Open
Anya-Gupta-05 wants to merge 2 commits into
bentoml:mainfrom
Anya-Gupta-05:fix/5246-mounted-asgi-timeout
Open

fix: apply timeout to mounted ASGI apps (#5246)#5621
Anya-Gupta-05 wants to merge 2 commits into
bentoml:mainfrom
Anya-Gupta-05:fix/5246-mounted-asgi-timeout

Conversation

@Anya-Gupta-05

Copy link
Copy Markdown

Closes #5246

Problem

traffic={"timeout": N} was applied to native BentoML API routes
but ignored for apps mounted via @bentoml.asgi_app. Mounted routes
ran under the default 60s timeout regardless of config.

Fix

Wrap each mounted app with TimeoutMiddleware at mount time in
ServiceAppFactory.__call__, using the existing self.timeout
value from the base class.

Test

Start service with traffic={"timeout": 10}, hit a mounted FastAPI
route that sleeps 15s — now returns 504 after 10s.

TimeoutMiddleware was applied to native @bentoml.api routes but
not to apps mounted via @bentoml.asgi_app / mount_asgi_app.
Wrap each mount_app with TimeoutMiddleware when timeout is set.
@Anya-Gupta-05 Anya-Gupta-05 requested a review from a team as a code owner May 25, 2026 06:29
@Anya-Gupta-05 Anya-Gupta-05 requested review from parano and removed request for a team May 25, 2026 06:29
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.

bug: Bentoml mounted FastAPI app doesn't apply timeout value

1 participant