ncr / rack-proxy

A request/response rewriting HTTP proxy. A Rack app.
MIT License
269 stars 94 forks source link

Rack::Proxy#call method hangs #66

Closed amitfriedman12 closed 7 years ago

amitfriedman12 commented 7 years ago

I have a custom class that overwrites the default Rack::Proxy functionality:

module Middleware
  class SOAProxy < Rack::Proxy

    attr_reader :app

    def initialize(app)
      @app = app
    end

    def call(env)
      if some_condition_is_met
        write_authorization_token(env)
        rewrite_proxy_host(env, proxy_host)
        rewrite_request_path(env)
        super(env)
      else
        app.call(env)
      end
    end

However I am having an issue that occurs when the super(env) code gets executed. Even after the local server which i hit with my API call returns a 200 response, the call method does not finish executing for another 5-10 seconds or so.

After looking into it, this is where the API call is made and where the hanging occurs. I would expect the call the http request to finish executing as soon as the local server returns the 200 response, but instead the code continues executing a few seconds later.

Any ideas how to further debug this? Using rails 3.2.16 and ruby 2.3.3.

velles commented 7 years ago

Few more details on this issue: 1) Fast Proxy - respond immediately after the targeting server is done - Rails 3.2.16 proxies to Rails 4 with puma server 2) Slow Proxy - respond takes 20-30s after the targeting server is done - Rails 3.2.16 proxies to Rails 5 API with puma server

kenzan100 commented 4 years ago

Did you guys find out what was the issue here?

kenzan100 commented 4 years ago

fyi for my case it was related to the header Connection: KeepAlive as per https://github.com/axsuul/rails-reverse-proxy/issues/34