Skip to content

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

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

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

Conversation

@doefimov

Copy link
Copy Markdown
Contributor

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 2 commits November 22, 2026 12:41
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.
@reshke
reshke force-pushed the backport/segment-reconfigurer-rel2 branch from a162d8c to f5f341e Compare November 22, 2026 07:41
@reshke
reshke requested a review from tuhaihe November 22, 2026 07:42
@reshke

reshke commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Should we add test_it_closes_each_connection_only_once to main ? Otherwise I'd prefer to remove test from this PR

@doefimov

doefimov commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Added test_it_closes_each_connection_only_once to main in #2393

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.

3 participants