Skip to content

Commit 001d624

Browse files
committed
Merge pull request #195 from moniker-dns/feature/tcp-transport
Handle publication failures in the TCP transport correctly
2 parents 829d665 + b5dcf33 commit 001d624

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

beaver/transports/tcp_transport.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# -*- coding: utf-8 -*-
22
import socket
3+
import errno
34
import time
45

56
from beaver.transports.base_transport import BaseTransport
7+
from beaver.transports.exception import TransportException
68

79

810
class TcpTransport(BaseTransport):
@@ -51,5 +53,18 @@ def callback(self, filename, lines, **kwargs):
5153
if kwargs.get('timestamp', False):
5254
del kwargs['timestamp']
5355

54-
for line in lines:
55-
self._sock.send(self.format(filename, line, timestamp, **kwargs) + "\n")
56+
try:
57+
for line in lines:
58+
self._sock.send(self.format(filename, line, timestamp, **kwargs) + "\n")
59+
except socket.error, e:
60+
self.invalidate()
61+
62+
if isinstance(e.args, tuple):
63+
if e[0] == errno.EPIPE:
64+
raise TransportException('Connection appears to have been lost')
65+
66+
raise TransportException('Socket Error: %s', e.args)
67+
except Exception:
68+
self.invalidate()
69+
70+
raise TransportException('Unspecified exception encountered') # TRAP ALL THE THINGS!

0 commit comments

Comments
 (0)