fix(init): strip trailing newline when writing DB_CONNECTION to s6 env file#75
Open
Timikana wants to merge 1 commit into
Open
fix(init): strip trailing newline when writing DB_CONNECTION to s6 env file#75Timikana wants to merge 1 commit into
Timikana wants to merge 1 commit into
Conversation
…ntainer env
The init script used "echo" to write the DB_CONNECTION value to
/run/s6/container_environment/DB_CONNECTION. Since echo appends a
newline, the file contains "sqlite\n" instead of "sqlite".
s6-overlay reads this file as the env value for child processes,
including PHP-FPM. Laravel config caching ("artisan optimize")
then captures DB_CONNECTION="sqlite\n" and persists it.
At request time Laravel attempts to resolve a connection named
"sqlite\n", which does not exist in config("database.connections"),
and throws:
InvalidArgumentException: Database connection [sqlite
] not configured.
Replacing echo with printf "%s" produces a clean value (no trailing
newline) and resolves the issue.
Reproduces with:
docker compose up -d using DB_CONNECTION sqlite (default)
Login attempt at /admin/login -> 500
Stack trace shows DatabaseManager throwing on "[sqlite\n]"
There was a problem hiding this comment.
Thanks for opening this pull request! Be sure to follow the pull request template!
Contributor
|
I am a bot, here are the test results for this PR:
|
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
The init script writes
DB_CONNECTIONto/run/s6/container_environment/DB_CONNECTIONusingecho, which appends a trailing newline. s6-overlay then propagates this trailing newline into the env var seen by PHP-FPM workers. Laravel caches config viaartisan optimizeduring init, so the cacheddatabase.defaultbecomes"sqlite\n".At request time, any code path that resolves a DB connection (login, eloquent queries, sessions stored in DB, etc.) throws:
(Note the literal newline inside the brackets in the message.)
Reproduction
/config/.envprovided, sqlite default):/admin/login, enter credentials, submit.APP_DEBUG=truethe error page shows:InvalidArgumentExceptionDatabase connection [sqlite\n] not configured.vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:226Fix
Replace
echo "sqlite" > /run/s6/container_environment/DB_CONNECTIONwithprintf "%s" "sqlite" > ...so the file contains exactlysqlite(no trailing newline).Verification
After applying:
config("database.default")returns the 6-byte stringsqlite(verified withod -c).The change is one line and only affects the sqlite branch of the existing conditional. The mysql/pgsql branches were not affected.