fix: return HTTP 503 on bootstrap error for /health endpoint#1961
Merged
kayjoosten merged 3 commits intomainfrom Apr 9, 2026
Merged
fix: return HTTP 503 on bootstrap error for /health endpoint#1961kayjoosten merged 3 commits intomainfrom
kayjoosten merged 3 commits intomainfrom
Conversation
Uncaught exceptions thrown during bootstrap (before Symfony starts) produced a PHP fatal error page with HTTP 200. Narrow the try-catch to only the env validation block so monitoring systems receive a 503 JSON response consistent with the monitor-bundle DOWN format, without interfering with response sending or kernel termination. Closes #1936
johanib
reviewed
Apr 7, 2026
Contributor
johanib
left a comment
There was a problem hiding this comment.
Did some digging. Your change seems the best solution 👍
Not really nice or elegant. But it works and I think its the only way.
One suggestion in the code, and maybe it's a good idea to also intercept errors in the regular fallback handler. Otherwise, in some scenario's the fallback might hijack errors, and do a 301 redirect instead of returning a 500 on the health endpoints..
Index: src/OpenConext/EngineBlockBundle/EventListener/FallbackExceptionListener.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/OpenConext/EngineBlockBundle/EventListener/FallbackExceptionListener.php b/src/OpenConext/EngineBlockBundle/EventListener/FallbackExceptionListener.php
--- a/src/OpenConext/EngineBlockBundle/EventListener/FallbackExceptionListener.php (revision 1cdd470e6c39b94a9a7344e3a471010344487772)
+++ b/src/OpenConext/EngineBlockBundle/EventListener/FallbackExceptionListener.php (date 1775571383912)
@@ -21,6 +21,7 @@
use EngineBlock_Exception;
use OpenConext\EngineBlockBridge\ErrorReporter;
use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -76,6 +77,15 @@
$exception->getMessage()
));
+ $path = $event->getRequest()->getPathInfo();
+ if (in_array($path, ['/health', '/internal/health', '/info', '/internal/info'], true)) {
+ $event->setResponse(new JsonResponse(
+ ['status' => 'DOWN', 'message' => $exception->getMessage()],
+ JsonResponse::HTTP_SERVICE_UNAVAILABLE
+ ));
+ return;
+ }
+
if ($exception instanceof EngineBlock_Exception) {
$this->errorReporter->reportError($exception, 'Caught Unhandled EngineBlock_Exception');
} else {
public/index.php
Outdated
Contributor
There was a problem hiding this comment.
Maybe include everything up to and including Request::createFromGlobals() into the try?
Wdyt?
…outes The fallback exception listener redirected all unhandled exceptions to the feedback page, which would return a 301 instead of an error status for the health and info endpoints. Return a JSON 503 response instead for these paths, consistent with the monitor-bundle DOWN format.
Include all pre-output bootstrap steps in the try-catch so that kernel boot failures (e.g. misconfigured bundles) also return 503 instead of a PHP error page with HTTP 200.
b781d37 to
d7d2fa5
Compare
johanib
approved these changes
Apr 9, 2026
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.
Summary
public/index.phpin atry-catch(\Throwable)so misconfiguration errors (e.g. missing/shortAPP_SECRET) return HTTP 503 instead of a PHP fatal error page with HTTP 200openconext/monitor-bundleDOWN convention:{"status":"DOWN","message":"..."}error_log()so bootstrap failures still appear in server logs/healthrouteTest Plan
APP_ENV=prodandAPP_SECRET=shortin devconf.env, restart engine container, hitGET https://engine.dev.openconext.local/health— expect HTTP 503 with{"status":"DOWN","message":"APP_SECRET must be at least 32 characters long in production."}.env, restart, hit/healthagain — expect HTTP 200{"status":"UP"}./vendor/bin/phpunit --configuration=./tests/phpunit.xml --testsuite=functional --filter=MonitorControllerTest— expect 3 tests passingCloses #1936