From 5c613c6ea98541df587193e861364c858a8a0abd Mon Sep 17 00:00:00 2001 From: Stephen Demjanenko Date: Fri, 3 May 2019 15:20:18 -0700 Subject: Rescue failed pipe resizes due to permissions When running: ``` require 'kgio' require 'raindrops' F_SETPIPE_SZ = 1031 if RUBY_PLATFORM =~ /linux/ Kgio::Pipe.new.each do |io| io.close_on_exec = true if defined?(F_SETPIPE_SZ) begin puts "setting" io.fcntl(F_SETPIPE_SZ, Raindrops::PAGE_SIZE) rescue Errno::EINVAL puts "rescued" rescue => e puts ["FAILED HARD", e].inspect end end end ``` on a few servers to test some Unicorn boot failures I saw: ``` ["FAILED HARD", #] ``` The `EPERM` error gets raised by the Linux kernel if: ``` (too_many_pipe_buffers_hard(pipe->user) || too_many_pipe_buffers_soft(pipe->user)) && !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN) ``` Given that the resize is not strictly necessary Unicorn should rescue the error and continue booting. --- lib/unicorn.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/unicorn.rb b/lib/unicorn.rb index 5f2134d..dd5dff4 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -123,6 +123,9 @@ module Unicorn io.fcntl(F_SETPIPE_SZ, Raindrops::PAGE_SIZE) rescue Errno::EINVAL # old kernel + rescue Errno::EPERM + # resizes fail if Linux is close to the pipe limit for the user + # or if the user does not have permissions to resize end end end -- cgit v1.2.3-24-ge0c7