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 been finished and then reponds.
  • Loading branch information
f3ndot committed Apr 22, 2020
1 parent 157e06c commit b07e99d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes.md
Expand Up @@ -5,6 +5,7 @@
Unreleased
---------

- Ensure `Rack::ContentLength` is loaded as middleware for correct Web UI responses [#4541]
- Avoid exception dumping SSL store in Redis connection logging [#4532]

6.0.7
Expand Down
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 b07e99d

Please sign in to comment.