From d22a31530a94f4809d49ff51b2c3e984de7a087b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 22 Sep 2021 13:29:47 +0200 Subject: net.server_epoll: Separate handling of "closed" from other errors The intent is to ensure 'ondisconnect' only gets called once, while giving buffered outgoing data a last chance to be delivered via the :close() path in case the connection was only shutdown in one direction. --- net/server_epoll.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'net') diff --git a/net/server_epoll.lua b/net/server_epoll.lua index ec2dd5b8..89b6ffe9 100644 --- a/net/server_epoll.lua +++ b/net/server_epoll.lua @@ -456,14 +456,14 @@ function interface:onreadable() self:onconnect(); self:onincoming(partial, err); end - if err ~= "timeout" then - if err == "closed" then - self:debug("Connection closed by remote"); - else - self:debug("Read error, closing (%s)", err); - end + if err == "closed" and self._connected then + self:debug("Connection closed by remote"); + self:close(err); + return; + elseif err ~= "timeout" then + self:debug("Read error, closing (%s)", err); self:on("disconnect", err); - self:close(); + self:destroy(); return; end end -- cgit v1.2.3