about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/yahns/http_client.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/yahns/http_client.rb b/lib/yahns/http_client.rb
index 849095e..a294511 100644
--- a/lib/yahns/http_client.rb
+++ b/lib/yahns/http_client.rb
@@ -224,9 +224,10 @@ class Yahns::HttpClient < Kgio::Socket # :nodoc:
     http_response_write(status, headers, body)
   end
 
+  # this is the env["rack.hijack"] callback exposed to the Rack app
   def hijack_proc(env)
     proc do
-      self.class.queue.queue_del(self) # EPOLL_CTL_DEL
+      hijack_cleanup
       env[RACK_HIJACK_IO] = self
     end
   end
@@ -253,12 +254,19 @@ class Yahns::HttpClient < Kgio::Socket # :nodoc:
     end while true
   end
 
-  def response_hijacked(fn)
+  # allow releasing some memory if rack.hijack is used
+  def hijack_cleanup
     # we must issue EPOLL_CTL_DEL before hijacking (if we issue it at all),
     # because the hijacker may close use before we get back to the epoll worker
     # loop.  EPOLL_CTL_DEL saves about 200 bytes of unswappable kernel memory,
     # so it can matter if we have lots of hijacked sockets.
-    self.class.queue.queue_del(self)
+    self.class.queue.queue_del(self) # EPOLL_CTL_DEL
+    @input = @input.close if @input
+    @hs = nil # no need for the HTTP parser anymore
+  end
+
+  def response_hijacked(fn)
+    hijack_cleanup
     fn.call(self)
     :ignore
   end