Skip to content

[REL_2_STABLE] Fix connection retries in gprecoverseg -r - #2376

Open
doefimov wants to merge 3 commits into
apache:REL_2_STABLEfrom
doefimov:backport/segment-reconfigurer-rel2
Open

doefimov wants to merge 3 commits into
apache:REL_2_STABLEfrom
doefimov:backport/segment-reconfigurer-rel2

Conversation

@doefimov

Copy link
Copy Markdown

Backport of 394e7c5.

Reset the connection before each retry and close it only if the connection succeeded. This prevents UnboundLocalError on the first failed connection and avoids closing a previous connection twice.

Test Plan

  • test_unit_segment_reconfigurer.py: 1/4 passed before the fix and 4/4 after it, on macOS and Linux. The new test catches a double close after a SQL error followed by a failed reconnect.
  • The related gprecoverseg and rebalance tests had the same 4 failures out of 11 on both revisions.

Checklist

  • This PR contains AI-assisted code generation

tuhaihe and others added 3 commits November 20, 2026 12:15
reconfigure() tries to connect again until the mirrors are promoted.
When the connection fails, the except block closes conn.  But when the
first connection fails, conn has no value yet:

  UnboundLocalError: local variable 'conn' referenced before assignment

The error goes out of the retry loop, so gprecoverseg and gpstart stop
and do not wait for the promotion.  In later tries, conn is the closed
connection of the previous try.

Set conn to None before each try, and close it only if it is set.
Now test_unit_segment_reconfigurer passes 3 of 3, instead of 1.

Greenplum fixed this as part of the change to psycopg2 (b5920e061b4).
That change does not apply to Cloudberry, which still uses PyGreSQL.

Backpatch-through: REL_2_STABLE
Assisted-by: Claude Code
(cherry picked from commit 394e7c5)
Check that a failed reconnect does not close the previous connection
again. Assert the timeout message after catching the exception.
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.

2 participants