Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be more verbose about UDP errors #14

Merged
merged 1 commit into from
May 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
license = f.read()

setup(name='swim-protocol',
version='0.3.7',
version='0.3.8',
author='Ian Good',
author_email='ian@icgood.net',
description='SWIM protocol implementation for exchanging cluster '
Expand Down
22 changes: 22 additions & 0 deletions swimprotocol/udp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import asyncio
import logging
from asyncio import BaseTransport, Condition, DatagramProtocol, \
DatagramTransport
from collections import deque
Expand All @@ -15,6 +16,8 @@

__all__ = ['SwimProtocol']

_log = logging.getLogger(__name__)


class SwimProtocol(DatagramProtocol, IO):
"""Implements :class:`~asyncio.DatagramProtocol` and
Expand Down Expand Up @@ -60,6 +63,25 @@ def datagram_received(self, data: bytes, addr: tuple[str, int]) -> None:
return
asyncio.create_task(self._push(packet))

def error_received(self, exc: Exception) -> None:
"""Called when a UDP send or receive operation fails.

See Also:
:meth:`asyncio.DatagramProtocol.error_received`

"""
_log.exception('UDP operation failed')

def connection_lost(self, exc: Optional[Exception]) -> None:
"""Called when the UDP socket is closed.

See Also:
:meth:`asyncio.BaseProtocol.connection_lost`

"""
_log.error('UDP connection lost: %s', exc)
self._transport = None

async def _push(self, packet: Packet) -> None:
async with self._queue_lock:
self._queue.append(packet)
Expand Down