Skip to content

Commit 2fbdad8

Browse files
committed
Clean up PoolManager resources on CrateLayer stop
To avoid resource leaks.
1 parent 460afc6 commit 2fbdad8

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Changes for crate
55
Unreleased
66
==========
77

8+
- Fixed a resource leak in ``CrateLayer``
9+
810
- Added ability to specify chunk size when getting a blob from the blob container
911

1012
2018/08/08 0.22.1

src/crate/testing/layer.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444

4545
CRATE_CONFIG_ERROR = 'crate_config must point to a folder or to a file named "crate.yml"'
4646
HTTP_ADDRESS_RE = re.compile(
47-
'.*\[(http|.*HttpServer.*)\s*] \[.*\] .*'
47+
r'.*\[(http|.*HttpServer.*)\s*] \[.*\] .*'
4848
'publish_address {'
49-
'(?:inet\[[\w\d\.-]*/|\[)?'
50-
'(?:[\w\d\.-]+/)?'
51-
'(?P<addr>[\d\.:]+)'
52-
'(?:\])?'
49+
r'(?:inet\[[\w\d\.-]*/|\[)?'
50+
r'(?:[\w\d\.-]+/)?'
51+
r'(?P<addr>[\d\.:]+)'
52+
r'(?:\])?'
5353
'}'
5454
)
5555

@@ -131,7 +131,6 @@ class CrateLayer(object):
131131

132132
tmpdir = tempfile.gettempdir()
133133
wait_interval = 0.2
134-
conn_pool = urllib3.PoolManager(num_pools=1)
135134

136135
@staticmethod
137136
def from_uri(uri,
@@ -157,7 +156,7 @@ def from_uri(uri,
157156
"""
158157
directory = directory or tempfile.mkdtemp()
159158
filename = os.path.basename(uri)
160-
crate_dir = re.sub('\.tar(\.gz)?$', '', filename)
159+
crate_dir = re.sub(r'\.tar(\.gz)?$', '', filename)
161160
crate_home = os.path.join(directory, crate_dir)
162161

163162
if os.path.exists(crate_home):
@@ -224,6 +223,7 @@ def __init__(self,
224223
self.env = env or {}
225224
self.env.setdefault('CRATE_USE_IPV4', 'true')
226225
self._stdout_consumers = []
226+
self.conn_pool = urllib3.PoolManager(num_pools=1)
227227

228228
crate_home = os.path.abspath(crate_home)
229229
if crate_exec is None:
@@ -319,7 +319,10 @@ def start(self):
319319
def stop(self):
320320
if self.process:
321321
self.process.terminate()
322-
self.process = None
322+
self.process.communicate(timeout=10)
323+
self.process.stdout.close()
324+
self.process = None
325+
self.conn_pool.clear()
323326
self.monitor.stop()
324327
self._clean()
325328

0 commit comments

Comments
 (0)