aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-07-11 09:39:21 +0200
committerKim Alvefur <zash@zash.se>2021-07-11 09:39:21 +0200
commitf814af50e3e7a024d8434219110c9c680ac2fb97 (patch)
tree6f6831ada8ed513d4d6dc8c1a5ddd1faee085835 /net
parent4439ef50e44a71cbd566bf5a127018d76d5b1ffa (diff)
downloadprosody-f814af50e3e7a024d8434219110c9c680ac2fb97.tar.gz
prosody-f814af50e3e7a024d8434219110c9c680ac2fb97.zip
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.
Diffstat (limited to 'net')
-rw-r--r--net/server_epoll.lua4
1 files changed, 3 insertions, 1 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua
index d2a1759b..f93809b4 100644
--- a/net/server_epoll.lua
+++ b/net/server_epoll.lua
@@ -499,8 +499,10 @@ function interface:write(data)
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();