From 39f00a0d315c5a2392a7676fbd6d95c3454f8170 Mon Sep 17 00:00:00 2001 From: Andrew Nelson Date: Tue, 23 Nov 2021 14:43:20 -0800 Subject: [PATCH] chore: InfluxDBClient.close should also close udp socket Currently, InfluxDBClient.close only works for http connections. The function explicitly skips closing the udp_socket member. UDP connections may not cost the system anything but leaving any sort of socket open can cause certain dynamic analysis tools to complain. With this patch we explicitly close the socket which quiets our linter's warnings. --- influxdb/client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/influxdb/client.py b/influxdb/client.py index adab4edc..9c4dc11a 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -143,6 +143,8 @@ def __init__(self, if use_udp: self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + else: + self.udp_socket = None if not path: self.__path = '' @@ -1199,9 +1201,11 @@ def send_packet(self, packet, protocol='json', time_precision=None): self.udp_socket.sendto(data, (self._host, self._udp_port)) def close(self): - """Close http session.""" + """Close any network connections for this client.""" if isinstance(self._session, requests.Session): self._session.close() + if self.udp_socket is not None: + self.udp_socket.close() def _parse_dsn(dsn):