Repository navigation
fix(fpc): graceful StopListen in the HTTPApplication provider - #635
Draft
edsontmarques wants to merge 1 commit into
Draft
edsontmarques wants to merge 1 commit into
edsontmarques wants to merge 1 commit into
Conversation
The FPC HTTPApplication provider inherited the abstract StopListen, which raises "StopListen not implemented", so Listen never returned. StopListen and StopListenGraceful now follow the documented order: mark the shutdown, stop accepting, turn keep-alive off, drain the requests in flight and signal the end. Listen returns only after the drain. A 100 ms accept-idle closes the race between OnListen and Run. Waits use atomic flags: a TEvent created at unit initialization breaks FPC programs built without cthreads. The new tests/fpc-graceful-shutdown check fails against the previous version (drain times out, in-onlisten exits 217) and runs in CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and change
The FPC HTTPApplication provider (the default provider for FPC console applications) does not override
StopListen. It inherits the abstract one, which raisesStopListen not implemented, althoughdoc/deployment.mdstops this shape withTHorse.StopListen.Listentherefore never returns, and a service cannot shut down in order.This patch gives the provider
StopListenandStopListenGraceful, following the order documented indoc/graceful-shutdown.md:SetIsShuttingDown);Listen, which returns only after the drain.StopListenuses a 5 s default;StopListenGraceful(ATimeoutMS)takes the limit explicitly. A second call is a no-op.A stop requested before
Runstarts accepting, for instance inside theListencallback, cannot be delivered throughTerminate, because there is no accept loop to break yet. The accept loop now runs with a 100 ms idle timeout, andOnAcceptIdlestops accepting once a stop was requested, so that early stop is still honoured andListenreturns without serving.TCustomWebApplication.Terminateforwards to the handler only the first time it is called, so the embedded server is switched off directly as well (FPC 3.3.1 and later, behind a version guard). The waits use atomic flags rather thanTEvent: an event created at unit initialization raisesESyncObjectExceptionin FPC programs built withoutcthreads.Horse has been useful in our projects, and this is a focused fix we would like to contribute back, in the same spirit as #632. The docs list this provider among the ones that drain (English and Portuguese).
Validation performed
All runs target Linux x86_64, with FPC
3.3.1-22012-g6564bb9b34-unpushed.tests/fpc-graceful-shutdown,drainmodeStopListenGracefulreturns beforeListentests/fpc-graceful-shutdown,in-onlistenmodeListenreturns without serving41c4b1c(this PR's base)drainhangs until the script's timeout (exit 124);in-onlistenraisesStopListen not implementedtests.yml(exception propagation, WebSocket EAGAIN, router lifetime, URL decoding, header hash, stream factory, provider config)Reproduce from the repository root:
The script is registered in
.github/workflows/tests.yml, after the router lifetime regression.HORSE_GRACEFUL_PORToverrides the port (default 9911).Validation still needed
Terminateplus the idle check. I could not run it here.🤖 Generated with Claude Code