Comparison

net/server_epoll.lua @ 11665:148075532021

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.
author Kim Alvefur <zash@zash.se>
date Sun, 11 Jul 2021 09:39:21 +0200
parent 11660:68f0196ece2a
child 11671:4e4e26e3df8d
comparison
equal deleted inserted replaced
11664:d83f8f44caea 11665:148075532021
497 t_insert(buffer, data); 497 t_insert(buffer, data);
498 else 498 else
499 self.writebuffer = { data }; 499 self.writebuffer = { data };
500 end 500 end
501 if not self._write_lock then 501 if not self._write_lock then
502 if cfg.opportunistic_writes then 502 if cfg.opportunistic_writes and not self._opportunistic_write then
503 self._opportunistic_write = true;
503 self:onwritable(); 504 self:onwritable();
505 self._opportunistic_write = nil;
504 return #data; 506 return #data;
505 end 507 end
506 self:setwritetimeout(); 508 self:setwritetimeout();
507 self:set(nil, true); 509 self:set(nil, true);
508 end 510 end