Skip to content

[BUG] NodeBackup::spawn_replica does not release a reserved port number during failure #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dmitry-lipetsk opened this issue May 4, 2025 · 1 comment · Fixed by #250
Labels

Comments

@dmitry-lipetsk
Copy link
Collaborator

dmitry-lipetsk commented May 4, 2025

Alter execution of TestTestgresCommon::test_replication_slots one port is not released.

Not released port is allocated in NodeBackup::spawn_primary that is called in NodeBackup::spawn_replica:

testgres/testgres/backup.py

Lines 187 to 192 in 5f8f5dd

with clean_on_error(self.spawn_primary(name=name,
destroy=destroy)) as node:
# Assign it a master and a recovery file (private magic)
node._assign_master(self.original_node)
node._create_recovery_conf(username=self.username, slot=slot)

NodeBackup::spawn_replica uses clean_on_error to destroy newly created node but clean_on_error does not call PostgresNode::free_port.

testgres/testgres/utils.py

Lines 314 to 326 in 5f8f5dd

@contextmanager
def clean_on_error(node):
"""
Context manager to wrap PostgresNode and such.
Calls cleanup() method when underlying code raises an exception.
"""
try:
yield node
except Exception:
# TODO: should we wrap this in try-block?
node.cleanup()
raise

Image

It seems to me, to fix this issue we can just call node.free_port method in clean_on_error immediatelly after node.cleanup.

Or we must to call node.free_port from node.cleanup.

@dmitry-lipetsk
Copy link
Collaborator Author

It is a part of work for #247.

@dmitry-lipetsk dmitry-lipetsk changed the title [BUG] NodeBackup::spawn_replica does not release port during failure [BUG] NodeBackup::spawn_replica does not release a reserved port number during failure May 4, 2025
dmitry-lipetsk added a commit to dmitry-lipetsk/testgres that referenced this issue May 4, 2025
We must release a port number after the shutdown and cleanup operation not before.

It is a part of work for postgrespro#249
dmitry-lipetsk added a commit to dmitry-lipetsk/testgres that referenced this issue May 4, 2025
…ed port number during failure

NodeBackup::spawn_replica uses an explict "rollback" code to destroy a newly allocated node to release a reserved port number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant