Skip to content

Commit 3cc79a3

Browse files
committed
Fix exceptions during connections
1 parent decad80 commit 3cc79a3

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Changes in FakeSMTPd 0.2.1
2+
==========================
3+
4+
Bug fixes
5+
---------
6+
7+
* Log exceptions raised during a connection, instead of aborting.
8+
19
Changes in FakeSMTPd 0.2.0
210
==========================
311

fakesmtpd/connection.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ def __init__(self, reader: StreamReader, writer: StreamWriter,
3838

3939
async def handle(self) -> None:
4040
logging.info("connection opened")
41+
try:
42+
await self._handle_connection()
43+
except Exception as exc:
44+
logging.warning(str(exc))
45+
finally:
46+
logging.info("connection closed")
47+
48+
async def _handle_connection(self) -> None:
4149
self._write_reply(SMTPStatus.SERVICE_READY,
4250
"{} FakeSMTPd Service ready".format(getfqdn()))
4351
while not self.reader.at_eof():
@@ -58,7 +66,6 @@ async def handle(self) -> None:
5866
elif code == SMTPStatus.SERVICE_CLOSING:
5967
break
6068
self.writer.close()
61-
logging.info("connection closed")
6269

6370
def _handle_command_line(self, line: str) -> SMTPStatus:
6471
logging.debug(f"received command: {line}")

0 commit comments

Comments
 (0)