diff --git a/lib/puma/client.rb b/lib/puma/client.rb index 8ff6c6fbdb..c7b5eabe4b 100644 --- a/lib/puma/client.rb +++ b/lib/puma/client.rb @@ -143,8 +143,7 @@ def reset(fast_check=true) return false else begin - if fast_check && - IO.select([@to_io], nil, nil, FAST_TRACK_KA_TIMEOUT) + if fast_check && @to_io.wait_readable(FAST_TRACK_KA_TIMEOUT) return try_to_finish end rescue IOError @@ -202,13 +201,13 @@ def try_to_finish def eagerly_finish return true if @ready - return false unless IO.select([@to_io], nil, nil, 0) + return false unless @to_io.wait_readable(0) try_to_finish end def finish(timeout) return if @ready - IO.select([@to_io], nil, nil, timeout) || timeout! until try_to_finish + @to_io.wait_readable(timeout) || timeout! until try_to_finish end def timeout! diff --git a/lib/puma/cluster.rb b/lib/puma/cluster.rb index 907611af22..3b301bb063 100644 --- a/lib/puma/cluster.rb +++ b/lib/puma/cluster.rb @@ -426,9 +426,7 @@ def run check_workers - res = IO.select([read], nil, nil, [0, @next_check - Time.now].max) - - if res + if read.wait_readable([0, @next_check - Time.now].max) req = read.read_nonblock(1) @next_check = Time.now if req == "!" diff --git a/lib/puma/cluster/worker.rb b/lib/puma/cluster/worker.rb index 8060f75847..05991dda2d 100644 --- a/lib/puma/cluster/worker.rb +++ b/lib/puma/cluster/worker.rb @@ -35,7 +35,7 @@ def run Thread.new do Puma.set_thread_name "worker check pipe" - IO.select [@check_pipe] + @check_pipe.wait_readable log "! Detected parent died, dying" exit! 1 end diff --git a/lib/puma/minissl.rb b/lib/puma/minissl.rb index 64534872fb..e780c721d8 100644 --- a/lib/puma/minissl.rb +++ b/lib/puma/minissl.rb @@ -162,7 +162,7 @@ def flush end def read_and_drop(timeout = 1) - return :timeout unless IO.select([@socket], nil, nil, timeout) + return :timeout unless @socket.wait_readable(timeout) case @socket.read_nonblock(1024, exception: false) when nil :eof diff --git a/lib/puma/request.rb b/lib/puma/request.rb index 8912db30f1..948992895f 100644 --- a/lib/puma/request.rb +++ b/lib/puma/request.rb @@ -201,7 +201,7 @@ def fast_write(io, str) begin n = io.syswrite str rescue Errno::EAGAIN, Errno::EWOULDBLOCK - if !IO.select(nil, [io], nil, WRITE_TIMEOUT) + unless io.wait_writable WRITE_TIMEOUT raise ConnectionError, "Socket timeout writing data" end @@ -419,7 +419,7 @@ def str_headers(env, status, headers, res_info, lines, requests, client) # of concurrent connections exceeds the size of the threadpool. res_info[:keep_alive] &&= requests < @max_fast_inline || @thread_pool.busy_threads < @max_threads || - !IO.select([client.listener], nil, nil, 0) + !client.listener.to_io.wait_readable(0) res_info[:response_hijack] = nil diff --git a/lib/puma/server.rb b/lib/puma/server.rb index 8bd2ae63c3..1de9ebfbc4 100644 --- a/lib/puma/server.rb +++ b/lib/puma/server.rb @@ -14,6 +14,7 @@ require 'puma/request' require 'socket' +require 'io/wait' require 'forwardable' module Puma diff --git a/test/helpers/integration.rb b/test/helpers/integration.rb index 05ab7a476a..c013c7de10 100644 --- a/test/helpers/integration.rb +++ b/test/helpers/integration.rb @@ -176,6 +176,7 @@ def get_worker_pids(phase = 0, size = workers) # used to define correct 'refused' errors def thread_run_refused(unix: false) if unix + DARWIN ? [Errno::ENOENT, Errno::EPIPE, IOError] : [Errno::ENOENT, IOError] else DARWIN ? [Errno::EBADF, Errno::ECONNREFUSED, Errno::EPIPE, EOFError] :