From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS12876 62.210.0.0/16 X-Spam-Status: No, score=-0.1 required=3.0 tests=AWL,BAYES_00, RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,RDNS_DYNAMIC,SPF_FAIL, SPF_HELO_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (62-210-37-82.rev.poneytelecom.eu [62.210.37.82]) by dcvr.yhbt.net (Postfix) with ESMTP id CFB7D20193 for ; Tue, 12 Jul 2016 21:11:40 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH 3/3] wbuf_lite: truncate StringIO when done Date: Tue, 12 Jul 2016 21:11:34 +0000 Message-Id: <20160712211134.23075-3-e@80x24.org> In-Reply-To: <20160712211134.23075-1-e@80x24.org> References: <20160712211134.23075-1-e@80x24.org> List-Id: 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