From 37d68b8c291e33865ec738f6f01319d3dde3c338 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 5 Jul 2019 10:19:04 +0200 Subject: [PATCH] dnsdist: Handle ENOTCONN on read() over TCP When a non-blocking connect() has returned `EINPROGRESS`, it looks like BSD can return `ENOTCONN` on `read()` even after a `write()` succeeded. --- pdns/dnsdist-tcp.cc | 2 +- pdns/tcpiohandler.hh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 994ba9a1bb..9ce3b74f4d 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -361,7 +361,7 @@ IOState tryRead(int fd, std::vector& buffer, size_t& pos, size_t toRead throw runtime_error("EOF while reading message"); } if (res < 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK) { + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOTCONN) { return IOState::NeedRead; } else { diff --git a/pdns/tcpiohandler.hh b/pdns/tcpiohandler.hh index 3e7f52b081..ac6525888a 100644 --- a/pdns/tcpiohandler.hh +++ b/pdns/tcpiohandler.hh @@ -214,7 +214,7 @@ public: throw runtime_error("EOF while reading message"); } if (res < 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK) { + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOTCONN) { return IOState::NeedRead; } else { @@ -250,7 +250,7 @@ public: throw runtime_error("EOF while sending message"); } if (res < 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK) { + if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOTCONN) { return IOState::NeedWrite; } else { -- 2.47.2