Skip to content

Commit 2351ee0

Browse files
authored
Fix tstool file descriptor leak (#8259)
1 parent 90b9552 commit 2351ee0

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

ydb/tools/tstool/tstool.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,26 @@ def main():
9191
tablet_ids = create_tablet(args.owner_idx, args.channels, args.count)
9292
print('TabletIds# %s' % ', '.join(map(str, tablet_ids)))
9393

94-
if args.action == 'initialize':
95-
cmd = text_format.Parse(args.proto_file.read(), TTestShardControlRequest.TCmdInitialize())
96-
if args.tsserver is not None:
97-
host, sep, port = args.tsserver.partition(':')
98-
port = int(port) if sep else default_tsserver_port
99-
sockaddr = None
100-
for _, _, _, _, sockaddr in socket.getaddrinfo(host, port, socket.AF_INET6):
101-
break
102-
if sockaddr is None:
103-
print('Failed to resolve hostname %s' % host, file=sys.stderr)
104-
sys.exit(1)
105-
cmd.StorageServerHost = sockaddr[0]
106-
with multiprocessing.Pool(None) as p:
107-
status = 0
108-
for r in p.imap_unordered(init_tablet, ((tablet_id, cmd) for tablet_id in tablet_ids), 1):
109-
if r is not None:
110-
sys.stderr.write(r)
111-
status = 1
112-
sys.exit(status)
94+
try:
95+
if args.action == 'initialize':
96+
cmd = text_format.Parse(args.proto_file.read(), TTestShardControlRequest.TCmdInitialize())
97+
if args.tsserver is not None:
98+
host, sep, port = args.tsserver.partition(':')
99+
port = int(port) if sep else default_tsserver_port
100+
sockaddr = None
101+
for _, _, _, _, sockaddr in socket.getaddrinfo(host, port, socket.AF_INET6):
102+
break
103+
if sockaddr is None:
104+
print('Failed to resolve hostname %s' % host, file=sys.stderr)
105+
sys.exit(1)
106+
cmd.StorageServerHost = sockaddr[0]
107+
with multiprocessing.Pool(None) as p:
108+
status = 0
109+
for r in p.imap_unordered(init_tablet, ((tablet_id, cmd) for tablet_id in tablet_ids), 1):
110+
if r is not None:
111+
sys.stderr.write(r)
112+
status = 1
113+
sys.exit(status)
114+
finally:
115+
if args.proto_file:
116+
args.proto_file.close()

0 commit comments

Comments
 (0)