From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.3 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 51ED71FAC6 for ; Mon, 9 May 2016 22:20:36 +0000 (UTC) From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH] http_client: set state to :ignore before hijack callback Date: Mon, 9 May 2016 22:20:46 +0000 Message-Id: <20160509222046.12542-1-e@80x24.org> List-Id: We need to set state as early as possible as any modification of our HttpClient object is unsafe after it is handed over to the underlying application. Otherwise, we could be clobbering a state set inside the hijack but before we hit the case statement in HttpClient#step_write. This bug should not affect current (known) uses of rack.hijack; but will be necessary for upcoming proxy_pass to support unbuffered proxy responses. --- lib/yahns/http_client.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/yahns/http_client.rb b/lib/yahns/http_client.rb index 272db85..1d64e08 100644 --- a/lib/yahns/http_client.rb +++ b/lib/yahns/http_client.rb @@ -22,8 +22,7 @@ def step_write case rv = @state.wbuf_flush(self) when :wait_writable, :wait_readable return rv # tell epoll/kqueue to wait on this more - when :ignore # :ignore on hijack - @state = :ignore + when :ignore # :ignore on hijack, @state already set in hijack_cleanup return :ignore when Yahns::StreamFile @state = rv # continue looping @@ -254,8 +253,9 @@ def yahns_read(bytes, buf) # (and complicated) as our hijack support will allow "un-hijacking" # the socket. def hijack_cleanup - # prevent socket from holding process up + # prevent socket from holding process exit up Thread.current[:yahns_fdmap].forget(self) + @state = :ignore @input = nil # keep env["rack.input"] accessible, though end -- e