-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
httpsys crashes node.exe process when serving static files #40
Comments
Fixing an issue where httpsys native module crashes node.exe process with Access Violation 0xc0000005, when responding to a request for a static file (or any large response).
Fixing an issue where httpsys native module crashes node.exe process with Access Violation 0xc0000005, when responding to a request for a static file (or any large response).
Now for the explanation of the problem and the fix. The crash happens in the native module void httpsys_write_callback(uv_async_t* handle, int status)
{
...
// Successful completion
if (0 == status)
{
// Call completed asynchronously - send notification to JavaScript.
Handle<Object> event = httpsys_create_event(uv_httpsys, HTTPSYS_WRITTEN);
httpsys_make_callback(event);
}
if (uv_httpsys->lastChunkSent)
{
// Response is completed - clean up resources
httpsys_free(uv_httpsys, FALSE); // <-- !!!!!!!!!!!! CRASH HERE !!!!!!!!!
uv_httpsys = NULL;
}
} This happens because of a combination of asynchronous completion and code's re-entrancy model. When the last chunk of data is sent back as a response through At that point, writing of the response stream had long finished, and caller would have indicated end of the stream by calling Back to if (!this._closed && this._requestContext.chunks)
this._initiate_send_next(); It sees the queue as not empty and initiates the next send, which in turn calls hr = HttpSendResponseEntityBody(
uv_httpsys->uv_httpsys_server->requestQueue,
uv_httpsys->requestId,
flags,
uv_httpsys->chunk.FromMemory.pBuffer ? 1 : 0,
uv_httpsys->chunk.FromMemory.pBuffer ? &uv_httpsys->chunk : NULL,
NULL,
NULL,
0,
&uv_httpsys->uv_async->async_req.overlapped,
NULL);
if (NO_ERROR == hr)
{
// Synchronous completion.
httpsys_write_callback(uv_httpsys->uv_async, 1);
}
else
{
ErrorIf(ERROR_IO_PENDING != hr, hr);
} Now, because the buffer is empty, http.sys API decides to be clever, and completes synchronously in this case (i.e. it has nothing to send anyway, plus it had already sent the whole response according to Content-Length header, so as far as it's concerned we're done). So the return code here is Remember from the top of this rant that we are already inside We now proceed to unwind the stack by returning from all these callbacks, until we are back where we originally started in the Since garbage is likely to be non-zero, the FIX: The fix is to stop this recursion on the first |
httpsys native module crashes with Access Violation (0xc0000005) when serving a static file over a certain size (at 30KB+), and takes down node.exe process.
Reproducing is fairly simple and happens every time:
The text was updated successfully, but these errors were encountered: