Skip to content

Commit e8bfeca

Browse files
KevinBlakeLopezmichalsnclaude
committed
docs: say reconnect() does not resume the lost transaction
Apply the review suggestion. The transaction-state reset only happens when ping() returns false, and PostgreSQL's pg_ping() can re-establish a broken connection and return true. The lost transaction is not resumed, later writes may autocommit, and the code that owns the whole transaction has to handle the failure before retrying. Drop the issue link from the changelog entry to match the changelog style. Co-authored-by: Michal Sniatala <459185+michalsn@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4a25d53 commit e8bfeca

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎user_guide_src/source/changelogs/v4.7.6.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Bugs Fixed
3636

3737
- **CLI:** Fixed a bug where ``CLI::promptByMultipleKeys()`` accepted a key missing from the options when it was below the last key, returning an empty selection, rejected a key above the last one when the options were not in key order, and offered ``0`` as the default when the first key was not ``0``.
3838
- **Commands:** Fixed a bug where generator commands did not sort the imports of a template with CRLF line endings.
39-
- **Database:** Fixed ``reconnect()`` so a replaced socket does not keep the transaction that died with the old connection. ``transDepth`` is cleared and the transaction status is failed before the new connection is opened, so a failed reconnect cannot still report success. OCI8 commit mode returns to autocommit. ``transComplete()`` does not report success. This applies when ``ping()`` reports the connection lost; PostgreSQL's ``pg_ping()`` reconnects a broken connection itself, so it is not covered. See `#10648 <https://github.com/codeigniter4/CodeIgniter4/issues/10648>`_.
39+
- **Database:** Fixed ``reconnect()`` so a replaced socket does not keep the transaction that died with the old connection. ``transDepth`` is cleared and the transaction status is failed before the new connection is opened, so a failed reconnect cannot still report success. OCI8 commit mode returns to autocommit. ``transComplete()`` does not report success. This applies when ``ping()`` reports the connection lost; PostgreSQL's ``pg_ping()`` reconnects a broken connection itself, so it is not covered.
4040
- **Format:** Fixed ``XMLFormatter`` so that an array key that becomes empty after sanitization no longer triggers a ``ValueError``; the fallback tag name ``item`` is used instead. Values that cannot be converted to a string, such as objects not implementing ``Stringable``, now throw a ``FormatException`` instead of a fatal ``Error``.
4141
- **Helpers:** Fixed a regression in v4.7.5 where ``set_value()`` threw a ``TypeError`` when the default value was not a string or an array, such as an integer, a float, ``null``, or a ``Stringable`` object. Such values are now converted to a string.
4242
- **HTTP:** Fixed a bug in ``ContentSecurityPolicy::setDefaultSrc()`` where passing an array of URIs resulted in an invalid ``'Array'`` directive.

‎user_guide_src/source/database/connecting.rst‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,17 @@ clears the transaction depth and marks the transaction failed before it
104104
opens the new connection, so ``transComplete()`` does not report success.
105105
On OCI8, commit mode returns to autocommit.
106106

107-
This only applies when ``ping()`` reports the connection lost. On PostgreSQL,
108-
``ping()`` uses ``pg_ping()``, which re-establishes a broken connection itself
109-
and returns true, so ``reconnect()`` does not clear the transaction state.
107+
The transaction-state reset described above only occurs when ``ping()``
108+
returns false. On PostgreSQL, ``ping()`` uses ``pg_ping()``, which can
109+
re-establish a broken connection and return true. In that case,
110+
``reconnect()`` does not clear the transaction state.
111+
112+
The lost transaction is not resumed on the new connection. Subsequent
113+
writes may be committed automatically and cannot be rolled back by
114+
calling ``transComplete()``. If the operation must remain atomic, stop
115+
executing its remaining queries. Handle the failure at the application
116+
level that owns the entire transaction, including any nested transaction
117+
groups, before deciding whether to retry the entire operation.
110118

111119
.. literalinclude:: connecting/007.php
112120
:lines: 2-

0 commit comments

Comments
 (0)