From e34e8e845dec33f78f2c2173fcd5c22a5b433bfb Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 28 Mar 2019 12:31:14 +0100 Subject: [PATCH 1/2] net.server_epoll: Handle LuaSec wantread/wantwrite conditions before callbacks (fixes #1333) This prevents the :set(true) call from resuming a connection that was paused in the onincoming callback. --- net/server_epoll.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/net/server_epoll.lua b/net/server_epoll.lua index 5c65d2278..cffd3a844 100644 --- a/net/server_epoll.lua +++ b/net/server_epoll.lua @@ -355,15 +355,18 @@ function interface:onreadable() self:onconnect(); self:on("incoming", data); else + if err == "wantread" then + self:set(true, nil); + err = "timeout"; + elseif err == "wantwrite" then + self:set(nil, true); + err = "timeout"; + end if partial and partial ~= "" then self:onconnect(); self:on("incoming", partial, err); end - if err == "wantread" then - self:set(true, nil); - elseif err == "wantwrite" then - self:set(nil, true); - elseif err ~= "timeout" then + if err ~= "timeout" then self:on("disconnect", err); self:destroy() return; From c422e8f13401e50cb13384227f97df3ad55605fd Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 28 Mar 2019 12:52:55 +0100 Subject: [PATCH 2/2] net.server_epoll: Skip delayed continuation read on paused connections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should prevent #1333 in cases where LuaSockets buffer is "dirty", i.e. contains more data after a read, where it gets resumed with a short delay. --- net/server_epoll.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/server_epoll.lua b/net/server_epoll.lua index cffd3a844..c41266e1a 100644 --- a/net/server_epoll.lua +++ b/net/server_epoll.lua @@ -373,7 +373,7 @@ function interface:onreadable() end end if not self.conn then return; end - if self.conn:dirty() then + if self._wantread and self.conn:dirty() then self:setreadtimeout(false); self:pausefor(cfg.read_retry_delay); else