Skip to content

Restore --timeout / timeoutSeconds inactivity shutdown - #1993

Open
waldekmastykarz wants to merge 1 commit into
dotnet:mainfrom
waldekmastykarz:symmetrical-doodle
Open

waldekmastykarz wants to merge 1 commit into
dotnet:mainfrom
waldekmastykarz:symmetrical-doodle

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Collaborator

Closes #1952

--timeout / timeoutSeconds were parsed but never used: InactivityTimer lost its caller in the Kestrel engine migration (9a15447), so Dev Proxy never exited after inactivity.

Changes

  • Moved InactivityTimer into DevProxy.Proxy.Kestrel and made Reset safe against a shutdown race.
  • KestrelProxyEngine takes an optional IHostApplicationLifetime. When TimeoutSeconds is set, it starts the timer after binding, resets it on every incoming proxy request (including CONNECT and keep-alive requests), and calls StopApplication when the timer elapses.
  • The host passes IHostApplicationLifetime to the engine.
  • Changed the v4.0.0 rc.schema.json description to match the CLI help: "Time in seconds after which Dev Proxy exits. Resets when Dev Proxy intercepts a request."

The docs (proxy-settings.md) still call the key timeout. That needs a separate fix in the docs repo.

Testing

  • New EngineInactivityTimeoutTests: the proxy stops when idle, doesn't stop without a timeout, and requests reset the countdown.
  • DevProxy.Integration.Tests (96) and DevProxy.Proxy.Kestrel.Tests (203) pass.
  • Manual run: devproxy --timeout 3 logs "No requests received in 3 seconds. Stopping Dev Proxy..." and exits.

…#1952

The inactivity timer lost its caller in the Kestrel engine migration, so
--timeout / timeoutSeconds were parsed but had no effect. The Kestrel engine
now starts the timer after binding, resets it on every incoming proxy
request, and stops the host when it elapses. Aligns the v4.0.0 schema
description with the CLI help.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e38816bc-97d1-40e5-adbb-4ef31390511d
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner October 21, 2026 13:58
Copilot AI balanced review requested due to automatic review settings October 21, 2026 13:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Timer startup timing, expiry/reset synchronization, and unsupported timeout values can cause premature shutdown or startup failure.

1 open issue
What changed in this PR

Restores inactivity shutdown for --timeout / timeoutSeconds in the Kestrel proxy engine, addressing #1952.

Changes:

  • Connects request activity and host shutdown to the inactivity timer.
  • Adds idle-timeout and countdown-reset integration tests.
  • Aligns the schema description with CLI help.
File Description
schemas/​v4.0.0/​rc.schema.json Clarifies inactivity timeout behavior.
DevProxy/​Extensions/​IServiceCollectionExtensions.cs Supplies host lifetime to the engine.
DevProxy.Proxy.Kestrel/​KestrelProxyEngine.cs Connects timeout expiry to shutdown.
DevProxy.Proxy.Kestrel/​Internal/​ProxyConnectionHandler.cs Reports incoming request activity.
DevProxy.Proxy.Kestrel/​Internal/​InactivityTimer.cs Relocates timer and handles resets after disposal.
DevProxy.Integration.Tests/​EngineInactivityTimeoutTests.cs Adds timeout regression coverage.

Review effort: Balanced

Comment on lines +71 to +72
using var inactivityTimer = configuration.TimeoutSeconds is { } timeoutSeconds && hostApplicationLifetime is not null
? new InactivityTimer(timeoutSeconds, () =>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Stale timer callbacks can trigger shutdown after activity, and accepted large timeout values can fail startup.

1 open issue

Review effort: Balanced

This branch has not been deployed

No deployments
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.

timeoutSeconds / --timeout has no effect

2 participants