[New-bugs-announce] [issue26403] Don't call sendto in DatagramRequestHandler if there is nothing to send

desbma report at bugs.python.org
Sun Feb 21 14:28:45 EST 2016

New submission from desbma:

When using socketserver to create a simple server for Unix Domain sockets (see server_dgram.py), and when sending data with a client that immediately shuts down (without waiting for a response, on Linux I test with 'echo data | nc -Uu -w 0 /tmp/s.socket')  I get this exception:

Exception happened during processing of request from /tmp/nc.XXXXsuGc1C
Traceback (most recent call last):
  File "/usr/lib/python3.4/socketserver.py", line 617, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python3.4/socketserver.py", line 344, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.4/socketserver.py", line 675, in __init__
  File "/usr/lib/python3.4/socketserver.py", line 752, in finish
    self.socket.sendto(self.wfile.getvalue(), self.client_address)
FileNotFoundError: [Errno 2] No such file or directory

The attached patch fixes this by checking if there is something to send before calling sendto.

Also I am wondering if we should catch FileNotFoundError (and possibly other exceptions) here, because with TCP or UDP, the server does not raise any exception if client is disconnected when finish is called in the handler.

Thank you

components: Macintosh
files: server_dgram.py
messages: 260632
nosy: desbma, ned.deily, ronaldoussoren
priority: normal
severity: normal
status: open
title: Don't call sendto in DatagramRequestHandler if there is nothing to send
versions: Python 3.5
Added file: http://bugs.python.org/file41990/server_dgram.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list