Skip to content

Commit

Permalink
Ignore internal ConnectionResetErrors (#8404)
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink authored Jan 21, 2025
2 parents f2c7e4b + 4f3e937 commit e153da9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/tribler/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from contextlib import contextmanager
from os.path import isfile
from traceback import format_exception
from typing import TYPE_CHECKING, Any, Generator, Type, cast
from typing import TYPE_CHECKING, Any, cast

import aiohttp
from ipv8.keyvault.crypto import default_eccrypto
Expand Down Expand Up @@ -43,6 +43,7 @@
from tribler.core.socks5.server import Socks5Server

if TYPE_CHECKING:
from collections.abc import Generator
from types import TracebackType

from tribler.core.database.store import MetadataStore
Expand Down Expand Up @@ -177,7 +178,7 @@ def register_rest_endpoints(self) -> None:
self.rest_manager.add_endpoint(StatisticsEndpoint())
self.rest_manager.add_endpoint(TorrentInfoEndpoint(self.download_manager))

def _except_hook(self, typ: Type[BaseException], value: BaseException, traceback: TracebackType | None) -> None:
def _except_hook(self, typ: type[BaseException], value: BaseException, traceback: TracebackType | None) -> None:
"""
Handle an uncaught exception.
Expand All @@ -196,7 +197,10 @@ def _asyncio_except_hook(self, loop: AbstractEventLoop, context: dict[str, Any])
Note2: ignored BaseExceptions are BaseExceptionGroup, GeneratorExit, KeyboardInterrupt and SystemExit
"""
exc = context.get("exception")
if isinstance(exc, Exception):
if isinstance(exc, ConnectionResetError):
logger.exception("Network unreachable: %s",
"".join(format_exception(exc.__class__, exc, exc.__traceback__)))
elif isinstance(exc, Exception):
logger.exception("Uncaught async exception: %s",
"".join(format_exception(exc.__class__, exc, exc.__traceback__)))
cast(EventsEndpoint, self.rest_manager.get_endpoint("/api/events")).on_tribler_exception(exc)
Expand Down

0 comments on commit e153da9

Please sign in to comment.