ruby-on-railsrackunicorn

Unicorn + Rails 7.1: TypeError: wrong argument type strio (expected strio) (TypeError)


User I am running a large Rails app with the Unicorn webserver in production. After upgrading from rails 7.0 to 7.1 I am getting the following issues:

Here is the error that happens for every request when running via Unicorn:

  127.0.0.1 - - [29/Nov/2023:09:53:30 +0100] "GET / HTTP/1.1" 500 51908 0.0197
TypeError: wrong argument type strio (expected strio) (TypeError)
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-3.0.8/lib/rack/lint.rb:390:in `external_encoding'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-3.0.8/lib/rack/lint.rb:390:in `check_input'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-3.0.8/lib/rack/lint.rb:332:in `check_environment'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-3.0.8/lib/rack/lint.rb:57:in `response'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-3.0.8/lib/rack/lint.rb:35:in `call'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-3.0.8/lib/rack/show_exceptions.rb:27:in `call'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-3.0.8/lib/rack/common_logger.rb:43:in `call'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-3.0.8/lib/rack/chunked.rb:102:in `call'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-3.0.8/lib/rack/content_length.rb:20:in `call'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:634:in `process_client'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:739:in `worker_loop'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:547:in `spawn_missing_workers'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:143:in `start'
    /Users/me/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/unicorn-6.1.0/bin/unicorn:128:in `<top (required)>'
    /Users/me/installs/ruby/3.2.2/bin/unicorn:25:in `load'
    /Users/me/installs/ruby/3.2.2/bin/unicorn:25:in `<main>'

It happens on all requests. I have of course tried updating Unicorn to the latest master from https://yhbt.net/unicorn.git and rack to the latest version. As far as I can tell, there are zero matching search results on Google for "wrong argument type strio". I also can’t find any relevant detail in the unicorn mailing list: https://yhbt.net/unicorn-public/ Neither have I been able to find anything relevant on https://github.com/rack/rack/issues

It seems to fail when calling external_encoding method here https://github.com/rack/rack/blob/f6c583adb0e863e524bacedaf594602964e01078/lib/rack/lint.rb#L393C59-L393C76 that method is implemented in C ... so no clue why that fails due to wrong argument type

What might be causing this and how do I further debug it?


Solution

  • I had a similar problem (although with the puma server). It looked like:

    [timestamp] Listen loop: #<TypeError: wrong argument type strio (expected strio)>
    

    (Sidenote: take a moment to appreciate the pure silliness of that message)

    The problem, which arose after a routine bundle update which only updated a bunch of minor versions of things, affected only "bare metal" mac development -- docker and linux were fine.

    The cause was that the debug gem (which we have in our development/test group of course) has a dependency of irb. irb at some point between 1.7.x and 1.10.x added a dependency on rdoc. rdoc depends on psych and psych depends on strio. We resolved it for the time being by adding a direct dependency (in the dev/test group) on irb and pinning it to ~> 1.7 to prevent it from going above. This removed rdoc, psych, and strio from our dependency tree.

    Note: We didn't bother checking to see if this was an irb 1.8, 1.9 or 1.10 change so it's very possible we could use 1.8 or 1.9 safely, I just didn't particularly care.

    so this:

    group :development, :test do
      gem 'debug', '~> 1.8'
    end
    

    became:

    group :development, :test do
      gem 'debug', '~> 1.8'
      gem 'irb', '~> 1.7'
    end
    
    

    Hope this was your problem also, as this was the only place on the Internet I even found anyone discussing this type of error.