mirror of
https://github.com/Flowseal/tg-ws-proxy.git
synced 2026-06-26 00:11:09 +03:00
may be fixes #1017
This commit is contained in:
@@ -521,14 +521,19 @@ async def _run(stop_event: Optional[asyncio.Event] = None):
|
|||||||
return_when=asyncio.FIRST_COMPLETED,
|
return_when=asyncio.FIRST_COMPLETED,
|
||||||
)
|
)
|
||||||
if stop_task in done:
|
if stop_task in done:
|
||||||
server.close()
|
for task in list(_client_tasks):
|
||||||
await server.wait_closed()
|
task.cancel()
|
||||||
|
if _client_tasks:
|
||||||
|
await asyncio.gather(
|
||||||
|
*_client_tasks, return_exceptions=True)
|
||||||
if not serve_task.done():
|
if not serve_task.done():
|
||||||
serve_task.cancel()
|
serve_task.cancel()
|
||||||
try:
|
try:
|
||||||
await serve_task
|
await serve_task
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
pass
|
pass
|
||||||
|
server.close()
|
||||||
|
await server.wait_closed()
|
||||||
else:
|
else:
|
||||||
stop_task.cancel()
|
stop_task.cancel()
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -364,6 +364,9 @@ def stop_proxy() -> None:
|
|||||||
loop.call_soon_threadsafe(stop_ev.set)
|
loop.call_soon_threadsafe(stop_ev.set)
|
||||||
if _proxy_thread:
|
if _proxy_thread:
|
||||||
_proxy_thread.join(timeout=5)
|
_proxy_thread.join(timeout=5)
|
||||||
|
if _proxy_thread.is_alive():
|
||||||
|
log.warning("Proxy thread did not stop within timeout; "
|
||||||
|
"port may still be in use")
|
||||||
_proxy_thread = None
|
_proxy_thread = None
|
||||||
log.info("Proxy stopped")
|
log.info("Proxy stopped")
|
||||||
|
|
||||||
@@ -371,7 +374,7 @@ def stop_proxy() -> None:
|
|||||||
def restart_proxy(cfg: dict, on_error: Callable[[str], None]) -> None:
|
def restart_proxy(cfg: dict, on_error: Callable[[str], None]) -> None:
|
||||||
log.info("Restarting proxy...")
|
log.info("Restarting proxy...")
|
||||||
stop_proxy()
|
stop_proxy()
|
||||||
time.sleep(0.3)
|
time.sleep(1.0)
|
||||||
start_proxy(cfg, on_error)
|
start_proxy(cfg, on_error)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user