Skip to content

Commit

Permalink
Ensure Rack::ContentLength is loaded as middleware
Browse files Browse the repository at this point in the history
6.0.5 removed Sidekiq::WebApplication's own Content-Length header calculation, expecting Rack to do it instead via some middleware. This was to fix an issue where New Relic would inject content into Sidekiq's Web UI after the hand crafted content length was calculated. While such middleware exists, it's not enabled by default (at least in a Rails app) and so the HTTP response doesn't have the header at all.

The absence of the header has caused unexpected behaviour in an nginx and HAProxy setup, causing each page load to take exactly 20 seconds. The suspicion is that, without the Content-Length response header, HAProxy waits a preset amount of time before deciding the body must have surely by finished and then reponds.
  • Loading branch information
f3ndot committed Apr 22, 2020
1 parent 157e06c commit 7dd6273
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/sidekiq/web.rb
Expand Up @@ -12,6 +12,7 @@
require "sidekiq/web/application"

require "rack/protection"
require "rack/content_length"

require "rack/builder"
require "rack/file"
Expand Down Expand Up @@ -172,6 +173,13 @@ def build_sessions

middlewares.unshift [[::Rack::Session::Cookie, options], nil]
end

# Since Sidekiq::WebApplication no longer calculates its own
# Content-Length response header, we must ensure that the Rack middleware
# that does this is loaded
unless using? ::Rack::ContentLength
middlewares.unshift [[::Rack::ContentLength], nil]
end
end

def build
Expand Down

0 comments on commit 7dd6273

Please sign in to comment.