Skip to content

Commit

Permalink
Cleanup server error-handling code. Fix #76
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Aug 23, 2017
1 parent ec99705 commit 40740c8
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ function process!(server::Server{T, H}, parser, request, i, tcp, rl, starttime,
else
rl.allowance -= 1.0
HTTP.@log(verbose, server.logger, "reading request bytes with readtimeout=$(options.readtimeout)")
buffer = readavailable(tcp)
# EH:
buffer = try
readavailable(tcp)
catch e
UInt8[]
end

This comment has been minimized.

Copy link
@samoconnor

samoconnor Aug 23, 2017

Contributor

Please try to avoid silently catching unspecified exceptions types. What if e is MethodError or ArgumentError or AssertionError?
This would silently ignore these errors and could result in situations that are very difficult to debug.

What type of e do you expect here?

This comment has been minimized.

Copy link
@quinnj

quinnj Aug 24, 2017

Author Member

The problem is that Base's underlying Libuv code is a little all over the place in terms of error-handling. Sometimes it's an AssertionError, sometimes a UVError, sometimes Argument. In any case, we're unable to get bytes off the wire, so in the next line we immediately abort processing the request.

length(buffer) > 0 || break
starttime[] = time() # reset the timeout while still receiving bytes
errno, headerscomplete, messagecomplete, upgrade = HTTP.parse!(request, parser, buffer)
Expand All @@ -127,7 +132,13 @@ function process!(server::Server{T, H}, parser, request, i, tcp, rl, starttime,
elseif headerscomplete && Base.get(HTTP.headers(request), "Expect", "") == "100-continue" && !alreadysent100continue
if options.support100continue
HTTP.@log(verbose, logger, "sending 100 Continue response to get request body")
write(tcp, HTTP.Response(100), options)
# EH:
try
write(tcp, HTTP.Response(100), options)
catch e
HTTP.@log(verbose, logger, e)
error = true
end
parser.state = HTTP.s_body_identity
alreadysent100continue = true
continue
Expand Down Expand Up @@ -156,16 +167,18 @@ function process!(server::Server{T, H}, parser, request, i, tcp, rl, starttime,
request = HTTP.Request()
else
get!(HTTP.headers(response), "Connection", "close")
close(tcp)
end
HTTP.@log(verbose, logger, "responding with response on connection i=$i")
verbose && (show(logger, response, options); println(logger))
try
write(tcp, response, options)
catch e
HTTP.@log(verbose, logger, e)
error = true
end
if !error
HTTP.@log(verbose, logger, "responding with response on connection i=$i")
verbose && (show(logger, response, options); println(logger))
try
write(tcp, response, options)
catch e
HTTP.@log(verbose, logger, e)
error = true
end
end
error && break
startedprocessingrequest = alreadysent100continue = false
end
Expand Down

0 comments on commit 40740c8

Please sign in to comment.