yahns Ruby server user/dev discussion
 help / color / mirror / Atom feed
* [PATCH] http_client: set state to :ignore before hijack callback
@ 2016-05-09 22:20 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-05-09 22:20 UTC (permalink / raw)
  To: yahns-public

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-05-09 22:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-09 22:20 [PATCH] http_client: set state to :ignore before hijack callback Eric Wong

yahns Ruby server user/dev discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhbt.net/yahns-public
	git clone --mirror http://ou63pmih66umazou.onion/yahns-public

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 yahns-public yahns-public/ https://yhbt.net/yahns-public \
		yahns-public@yhbt.net yahns-public@rubyforge.org
	public-inbox-index yahns-public

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.yahns
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.yahns
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	yahns.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git