Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions spec/std/http/server/request_processor_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require "spec"
require "log/spec"
require "http/server/request_processor"
require "../../../support/io"
require "../../../support/tempfile"

private def requestize(string)
string.gsub('\n', "\r\n")
Expand Down Expand Up @@ -268,6 +269,22 @@ describe HTTP::Server::RequestProcessor do
logs.entry.exception.should be_a(IO::Error)
end

it "handles closed UNIXSocket without broken pipe" do
with_tempfile("request_processor.sock") do |path|
server = UNIXServer.new(path)
client = UNIXSocket.new(path)
server.accept do |sock|
sock.sync = false
client.send "GET / HTTP/1.1\r\n\r\n"
processor = HTTP::Server::RequestProcessor.new do |context|
client.close
context.response.puts "hello"
end
processor.process(sock, sock)
end
end
end

it "catches raised error on handler and retains context from handler" do
exception = Exception.new "OH NO"
processor = HTTP::Server::RequestProcessor.new { Log.context.set foo: "bar"; raise exception }
Expand Down
8 changes: 7 additions & 1 deletion src/http/server/request_processor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ class HTTP::Server::RequestProcessor
context = Context.new(request, response)

Log.with_context do
@handler.call(context)
begin
@handler.call(context)
ensure
if output.is_a?(IO::Buffered)
output.sync = true
end
end
rescue ex : ClientError
Log.debug(exception: ex.cause) { ex.message }
rescue ex
Expand Down
Loading