Repository navigation
Conversation
… failure The server goroutine was never shut down explicitly, and an unexpected server error called logrus.Fatalf, which exits immediately and skips deferred cleanup. - Keep the http.Server reachable and call Shutdown on a fresh 15s context (the signal context is already cancelled). If it fails or times out, log it and force-close with Close, reporting any close error. - Treat http.ErrServerClosed as expected only after a requested shutdown; any other server exit is a failure. - Shut down HTTP before draining telemetry (fresh 5s context) so requests finishing during shutdown can still emit it. - Replace Fatalf with a returned exit code: main now calls os.Exit(runApplication()), so deferred cleanup runs before a non-zero exit. - Close the shared sql.DB pool via defer, after the HTTP server stops. - Cancel the signal context after shutdown so context-bound background work stops before the pools close. Shutdown does not stop running flows or background services, and does not wait for hijacked (WebSocket) connections. Signed-off-by: Yaash Singhh <YASHVSINGH27+git@GMAIL.COM>
- Active request completes before graceful shutdown returns, and Close is not called. - Deadline expiry is reported (context.DeadlineExceeded), Close is called once, and the stuck connection is cut. - A forced-close error is reported alongside the shutdown error. - http.ErrServerClosed after a requested shutdown is not an error; an unrequested one is. A server error racing the signal is not lost. - Unexpected server failure shuts the server down, drains telemetry, runs deferred cleanup in that order, and returns exit code 1. - A real listen failure (address in use) returns 1 and still drains. - A re-executed child process confirms the real exit status is 1 and deferred cleanup ran before exit. No sleeps, external network, PostgreSQL, Docker or LLM providers. Signed-off-by: Yaash Singhh <YASHVSINGH27+git@GMAIL.COM>
… failure The server goroutine was never shut down explicitly, and an unexpected server error called logrus.Fatalf, which exits immediately and skips deferred cleanup. - Keep the http.Server reachable and call Shutdown on a fresh 15s context (the signal context is already cancelled). If it fails or times out, log it and force-close with Close, reporting any close error. - Treat http.ErrServerClosed as expected only after a requested shutdown; any other server exit is a failure. - Shut down HTTP before draining telemetry (fresh 5s context) so requests finishing during shutdown can still emit it. - Replace Fatalf with a returned exit code: main now calls os.Exit(runApplication()), so deferred cleanup runs before a non-zero exit. - Close the shared sql.DB pool via defer, after the HTTP server stops. - Cancel the signal context after shutdown so context-bound background work stops before the pools close. Shutdown does not stop running flows or background services, and does not wait for hijacked (WebSocket) connections. Signed-off-by: Yaash Singhh <YASHVSINGH27+git@GMAIL.COM>
Signed-off-by: Yaash Singhh <YASHVSINGH27+git@GMAIL.COM>
yash27git
force-pushed
the
http/Shutdown
branch
from
October 28, 2026 15:47
46791a3 to
3fcf33f
Compare
Author
|
I found and fixed a source/test separation mistake: Could a maintainer please help with the remaining merge blockers?
|
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.
Description of the Change
Problem
The API HTTP server was started in a goroutine but was not explicitly shut down before telemetry and shared database resources were cleaned up. An unexpected server error used a fatal exit path that could skip deferred cleanup.
Solution
Closes #480
Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps
go test -race ./cmd/pentagifrom thebackenddirectory.go vet ./cmd/pentagifrom thebackenddirectory.Test Results
The production source was restored to
backend/cmd/pentagi/main.go; test code remains inbackend/cmd/pentagi/main_test.go. Tests and vet have not been run from this chat environment, so no passing result is claimed. CI status for the repaired commit is pending/needs verification.Security Considerations
No authentication, authorization, or network exposure changes are intended. Shutdown uses bounded contexts to avoid hanging indefinitely.
Performance Impact
No steady-state request-path changes are intended. Shutdown can wait up to 15 seconds for active HTTP requests before forcing close.
Documentation Updates
No user-facing API or configuration changes are intended.
Deployment Notes
No new environment variables, migrations, or deployment steps are required.
Checklist
Code Quality
go fmtandgo vet(for Go code)pnpm run lint(for TypeScript/JavaScript code)Security
Compatibility
Documentation
Additional Notes
The source/test separation was repaired in commit
46791a3647030e749ffd15ecf81a833669bee361. Please review the resulting diff and CI before merging.