unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: Exception with rails and devise
  2023-12-13 14:01 11% Exception with rails and devise Luca Berruti
@ 2023-12-14 23:09  0% ` Eric Wong
  0 siblings, 0 replies; 6+ results
From: Eric Wong @ 2023-12-14 23:09 UTC (permalink / raw)
  To: Luca Berruti; +Cc: unicorn-public

Luca Berruti <nadirio@gmail.com> wrote:
> Hello,
> 
> Unicorn 6.1.0 raises this exception when running on Rails 7.1.2 and Devise 4.9.3 within the production environment:
> 
> E, [2023-12-13T13:38:12.560072 #20] ERROR -- : app error: undefined method `=~' for ["_app_session=KbIfGKW%2FGniK%2B7V6boKx8Gh4VYYlk45gI14J5%2F4pSmJQkl890zAknDviSCWCBY4Jx%2FIa86Et1h%2Bad1laCN8sVf%2B9IgtgvN%2BhVLrHBYb9zqmX43LyNqKTEOaEfbU0H6EMEDS6TVJqmtP%2FVzGTf08uP8wgQFMCM6t5jWahl4h9dc47jC96h8BTF8%2FQDXHWPpcj6yzCC3aXjZqm7k2LEPQfXdmXJPwXS57sEYNk518vYWg%2BVOop16o7Lwqh3enXJVd1w%2F6CRFt5cFFlzsDHB7%2FA4%2BPWNLU%3D--v8qFRntrlxCgtLDy--7bldsiyqYyL2eow3kk348A%3D%3D; path=/; secure; httponly; SameSite=Lax"]:Array (NoMethodError)

That looks like a Rack 3 response with an array and 6.1.0
doesn't support Rack 3.  This patch ought to work:

https://yhbt.net/unicorn-public/ZHlX3HkxP6mK16If@jeremyevans.local/raw

(commit 9d7bab0bc2211b20806d4d0289a7ea992e49a8a1 in unicorn.git)

I'll try to get a unicorn 7.x release soon but tests take
forever to run on ancient HW and I need to ration releases to
keep download counts low in order to stay under the MFA
threshold on Rubygems.org

I don't ever want users viewing me as trustworthy nor liable for
anything I do, so no MFA nor sigs from me; just source + docs :>

^ permalink raw reply	[relevance 0%]

* Exception with rails and devise
@ 2023-12-13 14:01 11% Luca Berruti
  2023-12-14 23:09  0% ` Eric Wong
  0 siblings, 1 reply; 6+ results
From: Luca Berruti @ 2023-12-13 14:01 UTC (permalink / raw)
  To: unicorn-public

Hello,

Unicorn 6.1.0 raises this exception when running on Rails 7.1.2 and Devise 4.9.3 within the production environment:

E, [2023-12-13T13:38:12.560072 #20] ERROR -- : app error: undefined method `=~' for ["_app_session=KbIfGKW%2FGniK%2B7V6boKx8Gh4VYYlk45gI14J5%2F4pSmJQkl890zAknDviSCWCBY4Jx%2FIa86Et1h%2Bad1laCN8sVf%2B9IgtgvN%2BhVLrHBYb9zqmX43LyNqKTEOaEfbU0H6EMEDS6TVJqmtP%2FVzGTf08uP8wgQFMCM6t5jWahl4h9dc47jC96h8BTF8%2FQDXHWPpcj6yzCC3aXjZqm7k2LEPQfXdmXJPwXS57sEYNk518vYWg%2BVOop16o7Lwqh3enXJVd1w%2F6CRFt5cFFlzsDHB7%2FA4%2BPWNLU%3D--v8qFRntrlxCgtLDy--7bldsiyqYyL2eow3kk348A%3D%3D; path=/; secure; httponly; SameSite=Lax"]:Array (NoMethodError)
E, [2023-12-13T13:38:12.560131 #20] ERROR -- : /usr/local/bundle/gems/unicorn-6.1.0/lib/unicorn/http_response.rb:43:in `block in http_response_write'
E, [2023-12-13T13:38:12.560152 #20] ERROR -- : /usr/local/bundle/gems/unicorn-6.1.0/lib/unicorn/http_response.rb:34:in `each'
E, [2023-12-13T13:38:12.560165 #20] ERROR -- : /usr/local/bundle/gems/unicorn-6.1.0/lib/unicorn/http_response.rb:34:in `http_response_write'
E, [2023-12-13T13:38:12.560176 #20] ERROR -- : /usr/local/bundle/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:645:in `process_client'
E, [2023-12-13T13:38:12.560186 #20] ERROR -- : /usr/local/bundle/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:739:in `worker_loop'
E, [2023-12-13T13:38:12.560206 #20] ERROR -- : /usr/local/bundle/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:547:in `spawn_missing_workers'
E, [2023-12-13T13:38:12.560226 #20] ERROR -- : /usr/local/bundle/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:143:in `start'
E, [2023-12-13T13:38:12.560239 #20] ERROR -- : /usr/local/bundle/gems/unicorn-6.1.0/bin/unicorn:128:in `<top (required)>'
E, [2023-12-13T13:38:12.560249 #20] ERROR -- : bin/unicorn:27:in `load'
E, [2023-12-13T13:38:12.560259 #20] ERROR -- : bin/unicorn:27:in `<main>'


Changing rails' "config.force_ssl" option to "false" makes things to work.

Looking at /usr/local/bundle/gems/unicorn-6.1.0/lib/unicorn/http_response.rb:43, it seems that the cookie header content is a string when force_ssl=false but becomes an array with force_ssl=true

best regards,
Luca


^ permalink raw reply	[relevance 11%]

* Re: Support for Rack 3 headers formatted as arrays
  @ 2023-01-11 11:12 10%       ` Jean Boussier
  0 siblings, 0 replies; 6+ results
From: Jean Boussier @ 2023-01-11 11:12 UTC (permalink / raw)
  To: Eric Wong, Martin Posthumus; +Cc: unicorn-public

Interestingly, this patch would also help with Ruby 3.2 compatibility.

Ruby 3.2 removed `Kernel#=~`, so when misbehaving app return header 
values in e.g. Integer
unicorn now choke on it:

app error: undefined method `=~' for 43747171631368:Integer (NoMethodError)
unicorn-6.1.0/lib/unicorn/http_response.rb:43:in `block in 
http_response_write'
unicorn-6.1.0/lib/unicorn/http_response.rb:34:in `each'
unicorn-6.1.0/lib/unicorn/http_response.rb:34:in `http_response_write'
unicorn-6.1.0/lib/unicorn/http_server.rb:645:in `process_client'

Whereas on 3.1 and older, `42 =~ /\n/` would simply not match and cast 
the header as a String.



^ permalink raw reply	[relevance 10%]

* Re: Rails 7 - Unicorn 6.1.0 -- reaped with preload_app
  2022-05-06 13:55 14% Rails 7 - Unicorn 6.1.0 -- reaped with preload_app Cédric Carrard
@ 2022-05-07 17:27  7% ` Eric Wong
  0 siblings, 0 replies; 6+ results
From: Eric Wong @ 2022-05-07 17:27 UTC (permalink / raw)
  To: cedric.carrard; +Cc: unicorn-public

Cédric Carrard <cedriccarrard@gmail.com> wrote:
> Hello
> 
> Since the update to rails 7 and ruby 3.1.1 I have errors with unicorn
> 6.1.0 (we use docker-compose, nginx, sidekiq, postgresql and
> unicorn-worker-killer).

You might need something in your before_fork / after_fork hooks
for sidekiq or anything else that might make connections...

more below...

> 1:10280 configurator.rb:49] Unicorn -- reaped #<Process::Status: pid
> 415 exit 1> worker=15

Is there anything else?

> Here is the unicorn configuration:
> 
> require 'semantic_logger'
> 
> worker_processes(File.read('/proc/cpuinfo').scan(/^processor\s*:/).size
> * (ENV['WORKERS_PER_CPU'] || 2).to_i)

Sidenote: Etc.nprocessors is available since Ruby 2.2 and more
portable than reading /proc/cpuinfo.

I also recommend starting with 1-2 workers whenever you're
debugging to help narrow things down.  Some (most) FD
sharing problems appear when going to 1 -> 2, and 2 is usually
as good as dozens (until system memory/FD limits are hit)

> timeout 300
> preload_app true
> listen(ENV["PORT"] || 3000)
> logger SemanticLogger['Unicorn']
> 
> before_fork do |server, _worker|
>   Signal.trap 'TERM' do
>     server.logger.info 'Unicorn master intercepting TERM and sending
> myself QUIT instead'
>     Process.kill 'QUIT', Process.pid
>   end
> 
>   defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect!

OK, I guess AR is for Postgres.  Any other things that need to
be handled here?  (e.g. sidekiq, sqlite, xapian, memcached, redis, ...).

"lsof -p $PID" on both master and any single worker can be used
to spot inadvertant FD sharing for things that may need to be
shared.

> end
> 
> after_fork do |server, _worker|
>   Signal.trap 'TERM' do
>     server.logger.info 'Unicorn worker intercepting TERM and doing
> nothing. Wait for master to send QUIT'
>   end
> 
>   SemanticLogger.reopen

I assume SemanticLogger is just a filesystem-based logger?
If it establishes a connection, maybe it needed to be
disconnected in before_fork.

>   defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection
> end
> 
> If I remove the preload_app it works (but apparently it is recommended
> to leave this setting)

Recommendations depend on needs vs willingness to make things work :)
Yes, preload_app saves memory and improves startup time; but it
requires deeper app knowledge to use correctly (as you're
finding out).

> Do you have any idea where the problem could be?

Maybe the above helps, but it's really your codebase nobody in
here knows...

I have no idea what SemanticLogger is, but having fewer dependencies
can help you narrow things down.  In other words, try the normal
logger.

If you don't know the app very well (e.g. inherited from someone
else); I'd start by editing out large sections of the codebase
to narrow things down.

^ permalink raw reply	[relevance 7%]

* Rails 7 - Unicorn 6.1.0 -- reaped with preload_app
@ 2022-05-06 13:55 14% Cédric Carrard
  2022-05-07 17:27  7% ` Eric Wong
  0 siblings, 1 reply; 6+ results
From: Cédric Carrard @ 2022-05-06 13:55 UTC (permalink / raw)
  To: unicorn-public

Hello

Since the update to rails 7 and ruby 3.1.1 I have errors with unicorn
6.1.0 (we use docker-compose, nginx, sidekiq, postgresql and
unicorn-worker-killer).

1:10280 configurator.rb:49] Unicorn -- reaped #<Process::Status: pid
415 exit 1> worker=15

Here is the unicorn configuration:

require 'semantic_logger'

worker_processes(File.read('/proc/cpuinfo').scan(/^processor\s*:/).size
* (ENV['WORKERS_PER_CPU'] || 2).to_i)
timeout 300
preload_app true
listen(ENV["PORT"] || 3000)
logger SemanticLogger['Unicorn']

before_fork do |server, _worker|
  Signal.trap 'TERM' do
    server.logger.info 'Unicorn master intercepting TERM and sending
myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, _worker|
  Signal.trap 'TERM' do
    server.logger.info 'Unicorn worker intercepting TERM and doing
nothing. Wait for master to send QUIT'
  end

  SemanticLogger.reopen

  defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection
end

If I remove the preload_app it works (but apparently it is recommended
to leave this setting)

Do you have any idea where the problem could be?

Thanks for your help

------------------------
Best regards

Cédric Carrard

^ permalink raw reply	[relevance 14%]

* [ANN] unicorn 6.1.0 - Rack HTTP server for fast clients and *nix
@ 2021-12-25 18:06  6% Eric Wong
  0 siblings, 0 replies; 6+ results
From: Eric Wong @ 2021-12-25 18:06 UTC (permalink / raw)
  To: ruby-talk, unicorn-public

unicorn is an HTTP server for Rack applications designed to only serve
fast clients on low-latency, high-bandwidth connections and take
advantage of features in Unix/Unix-like kernels.  Slow clients should
only be served by placing a reverse proxy capable of fully buffering
both the the request and response in between unicorn and slow clients.

Disclaimer:

Due to its ability to tolerate crashes and isolate clients, unicorn
is unfortunately known to prolong the existence of bugs in applications
and libraries which run on top of it.

Consider this just an announcement to inform existing users of a
new version, not something to convince you to switch to something
that set the entire Ruby world back decades in terms of concurrency.

Note:
.onion URLs below are available for Tor users and can reduce
our operating costs:

* https://yhbt.net/unicorn/
  http://unicorn.7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/
* public list: unicorn-public@yhbt.net
* mail archives: https://yhbt.net/unicorn-public/
  http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/unicorn-public/
* git clone https://yhbt.net/unicorn.git
  torsocks git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/unicorn.git
* https://yhbt.net/unicorn/NEWS.atom.xml
  http://unicorn.7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/NEWS.atom.xml
* nntps://news.public-inbox.org/inbox.comp.lang.ruby.unicorn
  nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.lang.ruby.unicorn
  imaps://yhbt.net/inbox.comp.lang.ruby.unicorn.0
  imap://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.lang.ruby.unicorn.0

Changes:

    This release reduces CPU usage for Linux 4.5+ in most cases.
    See "[PATCH 6/6] use EPOLLEXCLUSIVE on Linux 4.5+" for more details:
      https://yhbt.net/unicorn-public/20211001030923.26705-7-bofh@yhbt.net/

    There's a couple of updates for Ruby 3.1, but we've finally
    started relying on Ruby 2.0.0 features after 9 years :P
    (so Ruby 1.9.3 users are stuck with older versions).

    And the usual round of doc updates and some build speedups.

    13 changes by the Bozo Doofus maintainer since v6.0.0:

          test_util: less excessive encoding tests
          drop Ruby 1.9.3 support, require 2.0+ for now
          drop unnecessary IO#close_on_exec=true assignment
          extconf.rb: get rid of unnecessary checks
          makefile: reduce unnecessary rebuilds
          HACKING: drop outdated information about pandoc
          http_server: get rid of Process.ppid check
          worker_loop: get rid of select() avoidance hack
          use EPOLLEXCLUSIVE on Linux 4.5+
          allow Ruby to deduplicate remaining globals
          epollexclusive: remove rb_gc_force_recycle call
          drop Ruby version warning, fix speling errer
          doc: v3 .onion updates, nntp => nntps, minor wording changes

^ permalink raw reply	[relevance 6%]

Results 1-6 of 6 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-12-25 18:06  6% [ANN] unicorn 6.1.0 - Rack HTTP server for fast clients and *nix Eric Wong
2022-05-06 13:55 14% Rails 7 - Unicorn 6.1.0 -- reaped with preload_app Cédric Carrard
2022-05-07 17:27  7% ` Eric Wong
2022-12-09 21:52     Support for Rack 3 headers formatted as arrays Martin Posthumus
2022-12-10  2:42     ` Eric Wong
2022-12-12 15:52       ` Martin Posthumus
2022-12-25 22:56         ` Eric Wong
2023-01-11 11:12 10%       ` Jean Boussier
2023-12-13 14:01 11% Exception with rails and devise Luca Berruti
2023-12-14 23:09  0% ` Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).