Skip to content

Conversation

@gheel-figma
Copy link
Contributor

@gheel-figma gheel-figma commented Nov 3, 2025

I've noticed we have a bunch of connections stuck in CLOSE_WAIT to Statsig on our Ruby servers using this SDK. I was able to fix this by calling flush on the response from post in post_logs, which consumes the response body.

Note that I do still see some connections in CLOSE_WAIT to a Cloudflare IP address too, so there may be other cases that this doesn't fix -- however this was the most egregious in our case.

Reproducing

Run the following:

#!/usr/bin/env ruby

# Before running this, export a server key like so:
# export STATSIG_SERVER_KEY='secret-your-key-here'

require "bundler/inline"

gemfile do
  source "https://rubygems.org"
  gem "statsig"
  gem "http"
  gem "connection_pool"
end

require "openssl"
require "http"
require "statsig"

# Disable SSL verification to skip certificate CRL errors
# This causes another issue around the connection pool get deadlocking
# on my local machine, but that's a problem for another time..
HTTP.default_options = {
  ssl_context: OpenSSL::SSL::SSLContext.new.tap do |ctx|
    ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
}

STATSIG_KEY = ENV["STATSIG_SERVER_KEY"]

options = StatsigOptions.new(
  { tier: "test" },
  local_mode: false,
  rulesets_sync_interval: 5,
  idlists_sync_interval: 5,
  logging_interval_seconds: 3,
  network_timeout: 2
)

Statsig.initialize(STATSIG_KEY, options)

# Generate events
test_user = StatsigUser.new({ "userID" => "test_#{Time.now.to_i}" })
puts "Generating events..."
20.times do |i|
  begin
    Statsig.check_gate(test_user, "test_gate")
    print "."
    $stdout.flush
  rescue => e
    print "Error: #{e.message}"
  end
  sleep 0.2
end

sleep 600

and then observe the connections accumulate..

$ netstat -an | grep CLOSE_WAIT

tcp4       0      0  192.168.5.133.65320    34.128.128.0.443       CLOSE_WAIT
tcp4       0      0  192.168.5.133.65232    34.128.128.0.443       CLOSE_WAIT
tcp4       0      0  192.168.5.133.65219    34.128.128.0.443       CLOSE_WAIT

@jmcfarland-figma
Copy link

I see this was merged in 2a7091f and tagged 2.8.1

Any chance this will be backported to the 2.5.x, 2.6.x and 2.7.x releases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants