Skip to content

Commit

Permalink
Remove TCP mode (#2169)
Browse files Browse the repository at this point in the history
  • Loading branch information
nateberkopec committed Mar 10, 2020
1 parent fc03781 commit 8d3db81
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 353 deletions.
10 changes: 6 additions & 4 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
* Add pumactl `thread-backtraces` command to print thread backtraces (#2053)
* Configuration: `environment` is read from `RAILS_ENV`, if `RACK_ENV` can't be found (#2022)
* Do not set user_config to quiet by default to allow for file config (#2074)
* `Puma.stats` now returns a Hash instead of a JSON string (#2086)
* `GC.compact` is called before fork if available (#2093)
* Add `requests_count` to workers stats. (#2106)
* Changed #connected_port to #connected_ports (#2076)

* Deprecations, Removals and Breaking API Changes
* `Puma.stats` now returns a Hash instead of a JSON string (#2086)
* `--control` has been removed. Use `--control-url` (#1487)
* `worker_directory` has been removed. Use `directory`
* `worker_directory` has been removed. Use `directory`.
* `tcp_mode` has been removed without replacement. (#2169)
* Changed #connected_port to #connected_ports (#2076)

* Bugfixes
* Windows update extconf.rb for use with ssp and varied Ruby/MSYS2 combinations (#2069)
Expand All @@ -24,7 +27,6 @@
* Simplify `Runner#start_control` URL parsing (#2111)
* Removed the IOBuffer extension and replaced with Ruby (#1980)


## 4.3.3 and 3.12.4 / 2020-02-28

* Bugfixes
Expand Down
96 changes: 0 additions & 96 deletions docs/tcp_mode.md

This file was deleted.

4 changes: 0 additions & 4 deletions lib/puma/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ def setup_options
end
end

o.on "--tcp-mode", "Run the app in raw TCP mode instead of HTTP mode" do
user_config.tcp_mode!
end

o.on "--early-hints", "Enable early hints support" do
user_config.early_hints
end
Expand Down
8 changes: 0 additions & 8 deletions lib/puma/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,6 @@ def rackup
def app
found = options[:app] || load_rackup

if @options[:mode] == :tcp
require 'puma/tcp_logger'

logger = @options[:logger]
quiet = !@options[:log_requests]
return TCPLogger.new(logger, found, quiet)
end

if @options[:log_requests]
require 'puma/commonlogger'
logger = @options[:logger]
Expand Down
11 changes: 0 additions & 11 deletions lib/puma/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,6 @@ def rackup(path)
@options[:rackup] = path.to_s
end

# Run Puma in TCP mode
#
def tcp_mode!
@options[:mode] = :tcp
end

def early_hints(answer=true)
@options[:early_hints] = answer
end
Expand Down Expand Up @@ -536,11 +530,6 @@ def directory(dir)
@options[:directory] = dir.to_s
end

# Run the app as a raw TCP app instead of an HTTP rack app.
def tcp_mode
@options[:mode] = :tcp
end

# Preload the application before starting the workers; this conflicts with
# phased restart feature. This is off by default.
#
Expand Down
8 changes: 0 additions & 8 deletions lib/puma/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ def output_header(mode)
log "* Version #{Puma::Const::PUMA_VERSION} (#{ruby_engine}), codename: #{Puma::Const::CODE_NAME}"
log "* Min threads: #{min_t}, max threads: #{max_t}"
log "* Environment: #{ENV['RACK_ENV']}"

if @options[:mode] == :tcp
log "* Mode: Lopez Express (tcp)"
end
end

def redirected_io?
Expand Down Expand Up @@ -158,10 +154,6 @@ def start_server
server.max_threads = max_t
server.inherit_binder @launcher.binder

if @options[:mode] == :tcp
server.tcp_mode!
end

if @options[:early_hints]
server.early_hints = true
end
Expand Down
109 changes: 0 additions & 109 deletions lib/puma/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ def inherit_binder(bind)
@binder = bind
end

def tcp_mode!
@mode = :tcp
end

# On Linux, use TCP_CORK to better control how the TCP stack
# packetizes our stream. This improves both latency and throughput.
#
Expand Down Expand Up @@ -176,107 +172,6 @@ def pool_capacity
@thread_pool and @thread_pool.pool_capacity
end

# Lopez Mode == raw tcp apps

def run_lopez_mode(background=true)
@thread_pool = ThreadPool.new(@min_threads,
@max_threads,
Hash) do |client, tl|

io = client.to_io
addr = io.peeraddr.last

if addr.empty?
# Set unix socket addrs to localhost
addr = "127.0.0.1:0"
else
addr = "#{addr}:#{io.peeraddr[1]}"
end

env = { 'thread' => tl, REMOTE_ADDR => addr }

begin
@app.call env, client.to_io
rescue Object => e
STDERR.puts "! Detected exception at toplevel: #{e.message} (#{e.class})"
STDERR.puts e.backtrace
end

client.close unless env['detach']
end

@events.fire :state, :running

if background
@thread = Thread.new do
Puma.set_thread_name "server"
handle_servers_lopez_mode
end
return @thread
else
handle_servers_lopez_mode
end
end

def handle_servers_lopez_mode
begin
check = @check
sockets = [check] + @binder.ios
pool = @thread_pool

while @status == :run
begin
ios = IO.select sockets
ios.first.each do |sock|
if sock == check
break if handle_check
else
begin
if io = sock.accept_nonblock
client = Client.new io, nil
pool << client
end
rescue SystemCallError
# nothing
rescue Errno::ECONNABORTED
# client closed the socket even before accept
begin
io.close
rescue
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
end
end
end
end
rescue Object => e
@events.unknown_error self, e, "Listen loop"
end
end

@events.fire :state, @status

graceful_shutdown if @status == :stop || @status == :restart

rescue Exception => e
STDERR.puts "Exception handling servers: #{e.message} (#{e.class})"
STDERR.puts e.backtrace
ensure
begin
@check.close
rescue
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
end

# Prevent can't modify frozen IOError (RuntimeError)
begin
@notify.close
rescue IOError
# no biggy
end
end

@events.fire :state, :done
end
# Runs the server.
#
# If +background+ is true (the default) then a thread is spun
Expand All @@ -290,10 +185,6 @@ def run(background=true)

@status = :run

if @mode == :tcp
return run_lopez_mode(background)
end

queue_requests = @queue_requests

@thread_pool = ThreadPool.new(@min_threads,
Expand Down
41 changes: 0 additions & 41 deletions lib/puma/tcp_logger.rb

This file was deleted.

Loading

0 comments on commit 8d3db81

Please sign in to comment.