Skip to content

Commit

Permalink
fix: shutdown web.Application on close()
Browse files Browse the repository at this point in the history
  • Loading branch information
null8626 committed Jun 6, 2024
1 parent 023d63e commit f80bd29
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion topgg/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# The MIT License (MIT)

# Copyright (c) 2021 Assanali Mukhanov
# Copyright (c) 2024 null8626

# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -70,7 +71,6 @@ class WebhookManager(DataContainerMixin):

def __init__(self) -> None:
super().__init__()
self.__app = web.Application()
self._is_running = False

@t.overload
Expand Down Expand Up @@ -120,6 +120,8 @@ async def start(self, port: int) -> None:
port (int)
The port to run the webhook on.
"""

self.__app = web.Application()
runner = web.AppRunner(self.__app)
await runner.setup()
self._webserver = web.TCPSite(runner, "0.0.0.0", port)
Expand All @@ -144,6 +146,7 @@ def app(self) -> web.Application:
async def close(self) -> None:
"""Stops the webhook."""
await self._webserver.stop()
await self.__app.shutdown()
self._is_running = False

def _get_handler(self, type_: WebhookType, auth: str, callback: t.Callable[..., t.Any]) -> _HandlerT:
Expand Down

0 comments on commit f80bd29

Please sign in to comment.