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: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 07AB2202F3 for ; Tue, 19 Jul 2016 22:24:43 +0000 (UTC) From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH 1/2] wbuf_lite: prevent clobbering responses Date: Tue, 19 Jul 2016 22:24:36 +0000 Message-Id: <20160719222437.23103-2-e@80x24.org> In-Reply-To: <20160719222437.23103-1-e@80x24.org> References: <20160719222437.23103-1-e@80x24.org> List-Id: All of our wbuf code assumes we append to existing buffers (files) since sendfile cannot deal otherwise. We also follow this pattern for StringIO to avoid extra data copies. --- lib/yahns/wbuf.rb | 1 + lib/yahns/wbuf_lite.rb | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/yahns/wbuf.rb b/lib/yahns/wbuf.rb index 583df10..3abc5f9 100644 --- a/lib/yahns/wbuf.rb +++ b/lib/yahns/wbuf.rb @@ -58,6 +58,7 @@ def wbuf_write(c, buf) end until @busy @tmpio ||= Yahns::TmpIO.new(c.class.output_buffer_tmpdir) + # n.b.: we rely on O_APPEND in TmpIO, here @sf_count += String === buf ? @tmpio.write(buf) : wbuf_writev(buf) # we spent some time copying to the FS, try to write to diff --git a/lib/yahns/wbuf_lite.rb b/lib/yahns/wbuf_lite.rb index 1902ce7..8a93ad1 100644 --- a/lib/yahns/wbuf_lite.rb +++ b/lib/yahns/wbuf_lite.rb @@ -33,6 +33,7 @@ def wbuf_write(c, buf) end until @busy @tmpio ||= StringIO.new(''.dup) # relies on encoding: binary above + @tmpio.seek(0, 2) # fake O_APPEND behavior @sf_count += @tmpio.write(buf) # we spent some time copying to the FS, try to write to @@ -45,12 +46,12 @@ def wbuf_write(c, buf) @busy = rv return rv else - raise "BUG: #{rv.nil? ? "EOF" : rv.inspect} on tmpio " \ + raise "BUG: #{rv.nil? ? 'EOF' : rv.inspect} on " + "tmpio.size=#{@tmpio.size} " \ "sf_offset=#@sf_offset sf_count=#@sf_count" end while @sf_count > 0 - # we're all caught up, try to prevent dirty data from getting flushed - # to disk if we can help it. + # we're all caught up, try to save some memory if we can help it. wbuf_abort @sf_offset = 0 @busy = false -- EW