# HG changeset patch # User Kim Alvefur # Date 1625989161 -7200 # Node ID 148075532021b377de127bb2cf72c33428e01e08 # Parent d83f8f44caea692347b57ccbedc14a75a8c346cd net.server_epoll: Prevent stack overflow of opportunistic writes net.http.files serving a big enough file on a fast enough connection with opportunistic_writes enabled could trigger a stack overflow through repeatedly serving more data that immediately gets sent, draining the buffer and triggering more data to be sent. This also blocked the server on a single task until completion or an error. This change prevents nested opportunistic writes, which should prevent the stack overflow, at the cost of reduced download speed, but this is unlikely to be noticeable outside of Gbit networks. Speed at the cost of blocking other processing is not worth it, especially with the risk of stack overflow. diff -r d83f8f44caea -r 148075532021 net/server_epoll.lua --- a/net/server_epoll.lua Fri Jul 09 22:06:58 2021 +0200 +++ b/net/server_epoll.lua Sun Jul 11 09:39:21 2021 +0200 @@ -499,8 +499,10 @@ self.writebuffer = { data }; end if not self._write_lock then - if cfg.opportunistic_writes then + if cfg.opportunistic_writes and not self._opportunistic_write then + self._opportunistic_write = true; self:onwritable(); + self._opportunistic_write = nil; return #data; end self:setwritetimeout();