Skip to content

Disable idle connection kickoff in drogon - #362

Merged
greenscientist merged 1 commit into
chairemobilite:v2cfrom
greenscientist:fixdrogonlongcalculation
Jul 27, 2026
Merged

Disable idle connection kickoff in drogon#362
greenscientist merged 1 commit into
chairemobilite:v2cfrom
greenscientist:fixdrogonlongcalculation

Conversation

@greenscientist

@greenscientist greenscientist commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

By default, drogon would kill a connection that is idle for 60 seconds. It's quite common for calculation to take more time than that, so we don't want this behavior.

We could consider in the future to set it to a really high value.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of long-running transit routing requests by keeping idle HTTP connections open long enough for calculations to finish, reducing premature disconnects during inactivity.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5920013b-6739-4395-8758-147128843c45

📥 Commits

Reviewing files that changed from the base of the PR and between 0a0e9b1 and 620b5fb.

📒 Files selected for processing (1)
  • connection_scan_algorithm/src/transit_routing_http_server.cpp
📜 Recent review details
⏰ Context from checks skipped due to timeout. (6)
  • GitHub Check: Test build on macOS-latest (memcached: true)
  • GitHub Check: Test build on macOS-latest (memcached: false)
  • GitHub Check: Test build on ubuntu-latest (memcached: true)
  • GitHub Check: Test build on ubuntu-latest (memcached: false)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: pr-build-check
🔇 Additional comments (1)
connection_scan_algorithm/src/transit_routing_http_server.cpp (1)

473-475: 🩺 Stability & Availability

Verify that 1200 seconds is a valid calculation bound.

This global timeout does not distinguish slow calculations from stuck ones: requests running longer than 20 minutes will still be disconnected, while stuck requests retain connections for that period. Since the expected maximum duration is currently unknown, make the bound configurable or add request-specific cancellation/heartbeat handling before relying on this constant.


Walkthrough

The Drogon HTTP server startup now sets the idle connection timeout to 1200 seconds before registering startup advice and running the server.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Suggested reviewers: tahini

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the change: it describes disabling Drogon's idle-connection timeout so long calculations can keep their connections open.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@connection_scan_algorithm/src/transit_routing_http_server.cpp`:
- Line 473: Update the Drogon server configuration around
setIdleConnectionTimeout so it no longer passes 0 globally. Set a bounded idle
timeout aligned with the maximum calculation duration, or implement
request-specific handling that preserves idle connection cleanup for unrelated
connections.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0c48468e-8cd4-49c5-abde-8ec16365820a

📥 Commits

Reviewing files that changed from the base of the PR and between 7304311 and 0a0e9b1.

📒 Files selected for processing (1)
  • connection_scan_algorithm/src/transit_routing_http_server.cpp
📜 Review details
⏰ Context from checks skipped due to timeout. (6)
  • GitHub Check: Test build on ubuntu-latest (memcached: false)
  • GitHub Check: Test build on macOS-latest (memcached: false)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: Test build on macOS-latest (memcached: true)
  • GitHub Check: Test build on ubuntu-latest (memcached: true)
  • GitHub Check: pr-build-check

drogon::app()
.addListener("0.0.0.0", programOptions.port)
.setThreadNum(4) // IO event loops only; calculations run on the compute pool
.setIdleConnectionTimeout(0) // 0 disables the kickoff of idle connection, we want to wait for long calculation

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate relevant files =="
fd -a 'transit_routing_http_server\.cpp|CMakeLists\.txt|drogon.*|package.*|requirements|Dockerfile|docker-compose|README|.*config.*' . | sed 's#^\./##' | head -200

echo
echo "== relevant snippet =="
if [ -f connection_scan_algorithm/src/transit_routing_http_server.cpp ]; then
  nl -ba connection_scan_algorithm/src/transit_routing_http_server.cpp | sed -n '440,500p'
fi

echo
echo "== drogon idle timeout/config references =="
rg -n "setIdleConnectionTimeout|idleConnectionTimeout|idle.*timeout|keepAlive|keep_alive|keepAliveTimeout|keepAlive" . -S --glob '!build/**' --glob '!node_modules/**' --glob '!dist/**' | head -300

Repository: chairemobilite/trRouting

Length of output: 1144


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== git changed files/stat =="
git status --short || true
git diff --stat || true

echo
echo "== inspect connection server around dispatch if present =="
if [ -f connection_scan_algorithm/src/transit_routing_http_server.cpp ]; then
  wc -l connection_scan_algorithm/src/transit_routing_http_server.cpp
  nl -ba connection_scan_algorithm/src/transit_routing_http_server.cpp | sed -n '1,180p'
fi

Repository: chairemobilite/trRouting

Length of output: 358


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== relevant snippet =="
awk '{printf "%6d\t%s\n", NR, $0}' connection_scan_algorithm/src/transit_routing_http_server.cpp | sed -n '430,490p'

echo
echo "== keepalive/idle timeout references =="
grep -RInE "setIdleConnectionTimeout|idleConnectionTimeout|idle.*timeout|keepAlive|keep_alive|keepAliveTimeout|keepAlive" . --exclude-dir=build --exclude-dir=result --exclude-dir=node_modules --exclude-dir=dist 2>/dev/null | head -300

echo
echo "== drogon version hints =="
grep -RInEi "drogon|libdrogon|drogon|drogon.*2\.[0-9]|0\.[0-9]+\.[0-9]+" . -E --exclude-dir=build --exclude-dir=result --exclude-dir=node_modules --exclude-dir=dist 2>/dev/null | head -200

Repository: chairemobilite/trRouting

Length of output: 8619


🌐 Web query:

Drogon HttpServer idleConnectionTimeout 0 infinite keeps idle connections

💡 Result:

Yes, in the Drogon framework, setting the idleConnectionTimeout to 0 effectively means that idle connections will not be closed by the server [1][2]. According to the official Drogon documentation and header files, the idleConnectionTimeout parameter defines the lifetime of a connection without any read or write activity [1][2]. While the default value is 60 seconds, setting this timeout to 0 instructs Drogon not to close idle connections [1][2]. This configuration can be applied either programmatically via the HttpAppFramework interface or through the framework's configuration file [1][2][3].

Citations:


🌐 Web query:

Drogon documentation connection idle timeout no reads writes idleConnectionTimeout=0 infinite

💡 Result:

In the Drogon framework, setting the idleConnectionTimeout (or idle_connection_timeout in the configuration file) to 0 disables the idle connection timeout mechanism [1][2][3]. This effectively makes connections "infinite" in terms of idle duration, meaning Drogon will not forcibly close connections due to inactivity (i.e., when there are no reads or writes) [1][2][4][5]. By default, this timeout is set to 60 seconds [4][6][7]. When a connection remains idle (no read or write activity) for longer than the specified timeout value, Drogon will close the connection [4][5]. You can configure this behavior in two primary ways: 1. Through the configuration file (JSON/YAML): Set the idle_connection_timeout key to 0 [4][6]. "idle_connection_timeout": 0 2. Programmatically using the app() interface: Use the setIdleConnectionTimeout method [1][8]. app.setIdleConnectionTimeout(0); This setting applies to the lifetime of connections managed by the framework, helping prevent the server from terminating connections that may otherwise be waiting for data [1][4][9].

Citations:


Avoid disabling idle timeouts globally.

0 removes the idle timeout for all connections, not just long-running calculation requests. Since Drogon treats idle connections as ones with no reads or writes, clients that stop sending data after start can remain open indefinitely and exhaust sockets/memory under load. Use a bounded timeout aligned with the maximum calculation duration, or handle long-running requests without disabling idle cleanup globally.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@connection_scan_algorithm/src/transit_routing_http_server.cpp` at line 473,
Update the Drogon server configuration around setIdleConnectionTimeout so it no
longer passes 0 globally. Set a bounded idle timeout aligned with the maximum
calculation duration, or implement request-specific handling that preserves idle
connection cleanup for unrelated connections.

@kaligrafy kaligrafy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Je sais pas

@kaligrafy

Copy link
Copy Markdown
Collaborator

I would put a very big value so stuck connection do timeout eventually

@greenscientist

Copy link
Copy Markdown
Contributor Author

I would put a very big value so stuck connection do timeout eventually

So what is the really big max of a calculation you can imagine for trRouting to do ?

@kaligrafy

Copy link
Copy Markdown
Collaborator

I don't know. There is no way to check if trrouting is indeed calculating or just stuck?

By default, drogon would kill a connection that is idle for 60 seconds. It's quite common for calculation to take
more time than that, so we don't want this behavior. We set it to a 20 minutes timeout, to still clean really idle connection.

We could consider in the future to send data on the pipe to keep the connection alive, or implement a response polling mecanism
@greenscientist
greenscientist force-pushed the fixdrogonlongcalculation branch from 0a0e9b1 to 620b5fb Compare July 27, 2026 22:09
@greenscientist
greenscientist requested a review from kaligrafy July 27, 2026 22:09
@greenscientist

Copy link
Copy Markdown
Contributor Author

I don't know. There is no way to check if trrouting is indeed calculating or just stuck?

CPU usage and timing clearly shows that trrouting was calculating

@greenscientist
greenscientist merged commit 76729fb into chairemobilite:v2c Jul 27, 2026
10 checks passed
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.

2 participants