Skip to content

fix: wire client_timeout and keep_alive_timeout through to Actix#1348

Open
sansyrox wants to merge 1 commit intomainfrom
fix/wire-server-timeouts
Open

fix: wire client_timeout and keep_alive_timeout through to Actix#1348
sansyrox wants to merge 1 commit intomainfrom
fix/wire-server-timeouts

Conversation

@sansyrox
Copy link
Copy Markdown
Member

@sansyrox sansyrox commented Mar 27, 2026

Summary

  • The Python API accepts client_timeout and keep_alive_timeout parameters and threads them through run_processesspawn_process, but spawn_process only called server.start(socket, workers) — silently dropping both timeout values.
  • The Rust Server::start hardcoded KeepAlive::Os and client_request_timeout(Duration::from_secs(0)), meaning the documented timeout configuration had zero effect.
  • This PR adds both parameters to the Rust Server::start signature and passes them to Actix's HttpServer builder.

Test plan

  • Existing integration tests pass (no behavior change for default values of 30s/20s)
  • Manual test: start server with client_timeout=2, send a request to a handler that sleeps 10s, verify the server cuts it off
  • Manual test: verify keep_alive_timeout causes idle connections to be closed after the configured duration

Made with Cursor

Summary by CodeRabbit

  • New Features
    • Added configurable client and keep-alive timeout parameters for the server, allowing users to customize connection lifecycle behavior to match their application requirements.

The Python API accepts client_timeout and keep_alive_timeout parameters
and threads them all the way to spawn_process, but they were never
passed to Server.start(). The Rust side hardcoded KeepAlive::Os and
client_request_timeout of 0 seconds, silently ignoring user config.

Pass both values through to Server.start() and use them when building
the Actix HttpServer.

Made-with: Cursor
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
robyn Ready Ready Preview, Comment Mar 27, 2026 0:03am

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

The pull request parameterizes server timeout configuration by passing client_timeout and keep_alive_timeout from the process pool to the server initialization, replacing hardcoded defaults with caller-provided values across Python and Rust layers.

Changes

Cohort / File(s) Summary
Python process pool
robyn/processpool.py
spawn_process passes client_timeout and keep_alive_timeout parameters (defaulting to 30 and 20) to server.start().
Rust server initialization
src/server.rs
Server::start method signature updated to accept client_timeout and keep_alive_timeout parameters; Actix HTTP server builder now uses these values to configure .keep_alive() and .client_request_timeout().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through timeout lands,
Where patient clients make their stands,
With configurable delays so fine,
Keep-alive and request—both align,
No hardcoded defaults today, hooray!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: wiring timeout parameters through to Actix configuration.
Description check ✅ Passed The description covers the issue, the fix, and a test plan, meeting the key content requirements, though some checklist items are unchecked.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/wire-server-timeouts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/server.rs`:
- Around line 280-282: The current use of client_request_timeout only affects
request header read time and does not stop long-running handlers; update the
server to enforce handler execution timeouts by adding a middleware or wrapping
handler execution with a timeout (e.g., add a tower::timeout::TimeoutLayer or
apply tokio::time::timeout around request handling) instead of relying on
client_request_timeout; locate where the server is configured (the block using
KeepAlive::Timeout, .workers, .client_request_timeout) and wrap the service or
router with a timeout layer (or modify the request-handling entrypoint to use
tokio::time::timeout) so that handler functions are aborted when they exceed the
desired duration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4b8934a6-de98-489b-9fc9-93150212c9df

📥 Commits

Reviewing files that changed from the base of the PR and between a54ff96 and 15ee1d5.

📒 Files selected for processing (2)
  • robyn/processpool.py
  • src/server.rs

Comment on lines +280 to +282
.keep_alive(KeepAlive::Timeout(std::time::Duration::from_secs(keep_alive_timeout)))
.workers(workers)
.client_request_timeout(std::time::Duration::from_secs(0))
.client_request_timeout(std::time::Duration::from_secs(client_timeout))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

In actix-web HttpServer, what exactly does client_request_timeout(Duration) control? Does it terminate a request when the handler itself runs longer than the timeout (e.g., handler sleeps 10 seconds)? Please cite official actix-web docs.

💡 Result:

In actix-web's HttpServer, client_request_timeout(Duration) controls the timeout for reading the client request head (headers). If the client does not transmit the entire set of headers within this time, the request is terminated with a 408 (Request Timeout) error. The default is 5000 milliseconds (5 seconds). To disable, set to Duration::ZERO. It does NOT terminate a request when the handler itself runs longer than the timeout (e.g., a handler that sleeps 10 seconds). This timeout only applies to initial header reading, not handler execution time.

Citations:


client_request_timeout does not enforce handler execution timeout (Line 282).

The manual test assumes that client_request_timeout will terminate requests when the handler runs longer than the timeout (e.g., handler sleeps 10 seconds). However, client_request_timeout only controls the timeout for reading client request headers, not handler execution time. A handler that sleeps 10 seconds will not be terminated by this setting. To enforce handler execution timeouts, a different mechanism is required (e.g., middleware-based timeout or tokio::time::timeout).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/server.rs` around lines 280 - 282, The current use of
client_request_timeout only affects request header read time and does not stop
long-running handlers; update the server to enforce handler execution timeouts
by adding a middleware or wrapping handler execution with a timeout (e.g., add a
tower::timeout::TimeoutLayer or apply tokio::time::timeout around request
handling) instead of relying on client_request_timeout; locate where the server
is configured (the block using KeepAlive::Timeout, .workers,
.client_request_timeout) and wrap the service or router with a timeout layer (or
modify the request-handling entrypoint to use tokio::time::timeout) so that
handler functions are aborted when they exceed the desired duration.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 27, 2026

Merging this PR will not alter performance

✅ 189 untouched benchmarks


Comparing fix/wire-server-timeouts (15ee1d5) with main (a54ff96)

Open in CodSpeed

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