Skip to content

Commit

Permalink
fix: close tcp connection on delete (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw authored Sep 9, 2024
1 parent d03d5c7 commit 69423d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions aiocloudweather/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ def __init__(self, proxied_sinks: list[DataSink], dns_servers: list[str]):
self.proxied_sinks = proxied_sinks
self.session = ClientSession(connector=TCPConnector(resolver=resolver))

def __del__(self):
"""Close the session when the object is deleted."""
if not self.session.closed:
self.session.close()

def close(self):
"""Close the session."""
if not self.session.closed:
self.session.close()

async def forward_wunderground(self, request: web.Request) -> web.Response:
"""Forward Wunderground data to their API."""
query_string = quote(request.query_string).replace("%20", "+")
Expand Down
1 change: 1 addition & 0 deletions aiocloudweather/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def update_config(
"""Update the proxy configuration."""
self.proxy_enabled = proxy_sinks and len(proxy_sinks) > 0
if self.proxy_enabled:
self.proxy.close()
self.proxy = CloudWeatherProxy(proxy_sinks, dns_servers or ["9.9.9.9"])

async def _new_dataset_cb(self, dataset: WeatherStation) -> None:
Expand Down

0 comments on commit 69423d2

Please sign in to comment.