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

Commitc3b25b2

Browse files
[#249] Fix of port number leak in NodeBackup::spawn_replica (#250)
This patch has the following changes:1) It adds a new argument release_resources to PostgresNode::cleanup method. Default value is False.2) It fixes a port number leak in NodeBackup::spawn_replica through explicit call of PostgresNode::cleanup(release_resources=True).Closes#249.
1 parent0b331e6 commitc3b25b2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

‎testgres/backup.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,19 @@ def spawn_replica(self, name=None, destroy=True, slot=None):
184184
"""
185185

186186
# Build a new PostgresNode
187-
withclean_on_error(self.spawn_primary(name=name,
188-
destroy=destroy))asnode:
187+
node=self.spawn_primary(name=name,destroy=destroy)
188+
assertnodeisnotNone
189189

190+
try:
190191
# Assign it a master and a recovery file (private magic)
191192
node._assign_master(self.original_node)
192193
node._create_recovery_conf(username=self.username,slot=slot)
194+
except:# noqa: E722
195+
# TODO: Pass 'final=True' ?
196+
node.cleanup(release_resources=True)
197+
raise
193198

194-
returnnode
199+
returnnode
195200

196201
defcleanup(self):
197202
"""

‎testgres/node.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ def __enter__(self):
231231
returnself
232232

233233
def__exit__(self,type,value,traceback):
234-
self.free_port()
235-
236234
# NOTE: Ctrl+C does not count!
237235
got_exception=typeisnotNoneandtype!=KeyboardInterrupt
238236

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

247+
self._release_resources()
248+
249249
def__repr__(self):
250250
return"{}(name='{}', port={}, base_dir='{}')".format(
251251
self.__class__.__name__,
@@ -663,6 +663,9 @@ def _try_shutdown(self, max_attempts, with_force=False):
663663
ps_output,
664664
ps_command)
665665

666+
def_release_resources(self):
667+
self.free_port()
668+
666669
@staticmethod
667670
def_throw_bugcheck__unexpected_result_of_ps(result,cmd):
668671
asserttype(result)==str# noqa: E721
@@ -1340,7 +1343,7 @@ def free_port(self):
13401343
self._port=None
13411344
self._port_manager.release_port(port)
13421345

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

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

1369+
ifrelease_resources:
1370+
self._release_resources()
1371+
13661372
returnself
13671373

13681374
@method_decorator(positional_args_hack(['dbname','query']))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp