Skip to content

Add retry mechanism and more detailed logging for connection issues#1

Open
danbarker wants to merge 2 commits into
masterfrom
2.0.0-beta3-retry-connect
Open

Add retry mechanism and more detailed logging for connection issues#1
danbarker wants to merge 2 commits into
masterfrom
2.0.0-beta3-retry-connect

Conversation

@danbarker

@danbarker danbarker commented Apr 9, 2025

Copy link
Copy Markdown
Member

Attempt to fix https://github.com/yearbook/ybmv3/issues/5581


Note

Medium Risk
Connection creation now delays up to ~200ms on failures and writes DSN-related details to error_log; retries could mask persistent misconfiguration briefly but do not change successful-path behavior.

Overview
Adds resilience and observability around Propel opening database connections, plus a small query hook typing fix.

Connection path: ConnectionFactory::create() now retries up to 3 attempts (initial + 2 retries) when the adapter throws AdapterException, with 100ms between tries. Each failed attempt is written to error_log, and the final failure becomes a ConnectionException that mentions the attempt count and preserves the last underlying error.

PDO layer: On PDOException during connect, PdoAdapter logs DSN (with password masked), message, and code via error_log before wrapping in AdapterException.

Unrelated fix: ModelCriteria::basePreUpdate() / preUpdate() drop the array type hint on $values so behavior hooks can pass either an update array or a Criteria (e.g. ON DELETE SET NULL emulation), with PHPDoc updated accordingly.

Reviewed by Cursor Bugbot for commit 3776f37. Bugbot is set up for automated code reviews on this repo. Configure here.

danbarker and others added 2 commits April 9, 2025 10:40
)

update() and doUpdate() are both written to accept either an array of values
or a Criteria (doUpdate has an explicit `$updateValues instanceof Criteria`
branch, and update()'s guard allows both). But basePreUpdate()/preUpdate()
typed the parameter `array &$values`, so passing a Criteria fatals:

    TypeError: ModelCriteria::basePreUpdate(): Argument #1 ($values) must be of
    type array, Propel\Runtime\ActiveQuery\Criteria given

This breaks the generated ON DELETE SET NULL emulation (doOnDeleteSetNull
builds a Criteria and calls update()) for any model that does not get a
behavior-generated basePreUpdate() override — QueryBuilder emits that override
with an *untyped* `&$values`, so behavior-ful models (e.g. versionable) already
work while timestampable-only / plain models hit the typed runtime method and
500.

Drop the `array` hint so the runtime matches the generator (and upstream),
letting both forms flow through to doUpdate().

Co-authored-by: Dan Barker <pat@yearbook.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3776f37. Configure here.

error_log(sprintf('PDO Connection Error: DSN: %s, Error: %s, Code: %s',
preg_replace('/password=.*?;/', 'password=***;', $dsn),
$e->getMessage(),
$e->getCode()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Password logged when last DSN segment

High Severity

The new PDO connection error logging tries to mask credentials with preg_replace('/password=.*?;/', ...), but Propel DSNs often end with ;password=... and no trailing semicolon. In that common layout the pattern never matches, so the real password is written to error_log on connection failure.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3776f37. Configure here.

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.

1 participant