And explain why this is doable for StringIO and not TmpIO,
which is file-backed.
---
 lib/yahns/wbuf_lite.rb | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/yahns/wbuf_lite.rb b/lib/yahns/wbuf_lite.rb
index 2da5349..1902ce7 100644
--- a/lib/yahns/wbuf_lite.rb
+++ b/lib/yahns/wbuf_lite.rb
@@ -108,6 +108,12 @@ def wbuf_close(client)
   end
 
   def wbuf_abort
-    @tmpio = @tmpio.close if @tmpio
+    # we can safely truncate since this is a StringIO, we cannot do this
+    # with a real file because zero-copy with sendfile means truncating
+    # a while could clobber in-flight data
+    if @tmpio
+      @tmpio.truncate(0)
+      @tmpio = @tmpio.close
+    end
   end
 end
-- 
EW

--
unsubscribe: yahns-public+unsubscr...@yhbt.net
archive: https://yhbt.net/yahns-public/

Reply via email to