Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[#249] Fix of port number leak in NodeBackup::spawn_replica#250

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletionstestgres/backup.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,14 +184,19 @@ def spawn_replica(self, name=None, destroy=True, slot=None):
"""

# Build a new PostgresNode
with clean_on_error(self.spawn_primary(name=name,
destroy=destroy)) as node:
node =self.spawn_primary(name=name, destroy=destroy)
assert node is not None

try:
# 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)
except: # noqa: E722
# TODO: Pass 'final=True' ?
node.cleanup(release_resources=True)
raise

return node
return node

def cleanup(self):
"""
Expand Down
12 changes: 9 additions & 3 deletionstestgres/node.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -231,8 +231,6 @@ def __enter__(self):
return self

def __exit__(self, type, value, traceback):
self.free_port()

# NOTE: Ctrl+C does not count!
got_exception = type is not None and type != KeyboardInterrupt

Expand All@@ -246,6 +244,8 @@ def __exit__(self, type, value, traceback):
else:
self._try_shutdown(attempts)

self._release_resources()

def __repr__(self):
return "{}(name='{}', port={}, base_dir='{}')".format(
self.__class__.__name__,
Expand DownExpand Up@@ -663,6 +663,9 @@ def _try_shutdown(self, max_attempts, with_force=False):
ps_output,
ps_command)

def _release_resources(self):
self.free_port()

@staticmethod
def _throw_bugcheck__unexpected_result_of_ps(result, cmd):
assert type(result) == str # noqa: E721
Expand DownExpand Up@@ -1340,7 +1343,7 @@ def free_port(self):
self._port = None
self._port_manager.release_port(port)

def cleanup(self, max_attempts=3, full=False):
def cleanup(self, max_attempts=3, full=False, release_resources=False):
"""
Stop node if needed and remove its data/logs directory.
NOTE: take a look at TestgresConfig.node_cleanup_full.
Expand All@@ -1363,6 +1366,9 @@ def cleanup(self, max_attempts=3, full=False):

self.os_ops.rmdirs(rm_dir, ignore_errors=False)

if release_resources:
self._release_resources()

return self

@method_decorator(positional_args_hack(['dbname', 'query']))
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp