Closed wch closed 5 years ago
This would suppress all fatal errors though, no? I'd be far more comfortable whitelisting the error codes we know to be benign (as we already do elsewhere in this file--maybe centralize).
Well, they're fatal in the sense that they're fatal to the HttpRequest object, but they're not problematic to the R process as a whole. I think reporting them to users as ERROR:
is unnecessarily alarming.
Maybe we could soften the language instead? Or both whitelist and soften the language.
I've made some changes to this PR, which greatly improve the debug logging.
logLevel()
, which sets the amount of information that will be printed to the console. Possible settings are OFF
, ERROR
, WARN
, INFO
, and DEBUG
, going from least information to the most information printed. The default is ERROR
.logLevel()
function is not exported, since it's just for debugging (and I want to put the same function in other packages).-DDEBUG_TRACE
to print debugging info. Now, the user just needs to call logLevel("DEBUG")
. uv_write
error messages are now printed only at INFO
or DEBUG
level.To test it out, run the following:
library(httpuv)
s <- startServer("0.0.0.0", 5000,
list(
call = function(req) {
list(
status = 200L,
headers = list('Content-Type' = 'text/html'),
body = "Hello world!"
)
}
)
)
httpuv:::logLevel("DEBUG")
Then visit 127.0.0.1:5000. The console will print lots of information, like this:
HttpRequest::_on_message_begin
HttpRequest::_on_url
HttpRequest::_on_header_field
HttpRequest::_on_header_value
HttpRequest::_on_header_field
HttpRequest::_on_header_value
HttpRequest::_on_header_field
HttpRequest::_on_header_value
HttpRequest::_on_headers_complete
HttpRequest::_schedule_on_headers_complete_complete
HttpRequest::_on_headers_complete_complete
HttpRequest::_on_message_complete
RWebApplication::getResponse
HttpRequest::responseScheduled
HttpRequest::_on_message_complete_complete
HttpResponse::writeResponse
HttpRequest::requestCompleted
HttpResponse::onResponseWritten
HttpResponse::~HttpResponse
HttpRequest::close
HttpRequest::_on_closed
WebSocketConnection::~WebSocketConnection
HttpRequest::~HttpRequest
This resolves rstudio/shiny#2371 and rstudio/shiny#2501.
On Unixes, httpuv applications occasionally printed
ERROR: [uv_write] bad file descriptor
, and on Windows, it wasERROR: [uv_write] broken pipe
.These messages occur when a httpuv app's
onHeaders
function schedules data to be written after the socket has already closed.To reproduce, run this app. If you wait 3 seconds, the browser will show "Hello headers!". If you close the browser window (or reload it) in less than 3 seconds, then the server will print out
ERROR: [uv_write] bad file descriptor
on Mac, andERROR: [uv_write] broken pipe
on Windows.The line of code that generates that message is at https://github.com/rstudio/httpuv/blob/605f668/src/httpresponse.cpp#L107
When this error happens, it is handled correctly, and everything gets cleaned up properly. This PR simply makes it not print out the error message, unless debugging has been enabled.