我的英语很不好。我尝试描述更多细节,但也许我不能道歉。
服务器发送了一个巨大的文件,并且在下载客户端时取消了该文件。
不久之后,Server尝试向客户端发送另一个文件,但是那一刻NodeJS崩溃了,没有抛出错误。
function file_send(stream, headers, address)
{
let ext = path.extname(address);
let type = mime.lookup(ext);
fs.access(address, fs.constants.F_OK, (err) =>
{
if(!err)
{
var start, end, chunksize;
function statCheck(stat, headers) {
headers['last-modified'] = stat.mtime.toUTCString();
if(headers['range'])
{
let range = headers.range;
let parts = range.replace(/bytes=/, "").split("-");
let partialstart = parts[0];
let partialend = parts[1];
start = parseInt(partialstart, 10);
end = partialend ? parseInt(partialend, 10) : stat.size-1;
chunksize = (end-start)+1;
console.log('RANGE: ' + start + ' - ' + end + ' = ' + chunksize);
headers['Content-Range'] = 'bytes ' + start + '-' + end + '/' + stat.size;
headers['Accept-Ranges'] = 'bytes';
headers['Content-Type'] = (type) ? type : 'application/octet-stream';
}
}
function onError(err) {
if (err.code === 'ENOENT') {
stream.respond({ ':status': 404 });
} else {
stream.respond({ ':status': 500 });
}
stream.end();
}
stream.respondWithFile(address, {'Content-Type': (type) ? type : null}, { statCheck, onError, waitForTrailers:false, start, end });
}
else
{
stream.respond({ ':status': 404 });
stream.end(`not found`);
}
});
}
错误:
Windows PowerShell[9644]: src\node_file.cc:220: Assertion `!reading_' failed.
1: node::DecodeWrite
2: node::DecodeWrite
3: uv_loop_fork
4: uv_loop_fork
5: v8::internal::FeedbackVector::New
6: v8::internal::FeedbackVector::New
7: v8::internal::FeedbackVector::New
8: v8::internal::FeedbackVector::New
9: 00000388F50041C1
Windows PowerShell[10484]: src\node_http2.cc:1970: Assertion `!this->IsDestroyed()' failed.
1: node::DecodeWrite
2: node::DecodeWrite
3: std::_Vector_alloc<std::_Vec_base_types<v8::internal::compiler::MoveOperands * __ptr64,v8::internal::ZoneAllocator<v8::internal::compiler::MoveOperands * __ptr64> > >::_Myfirst
4: v8::internal::OptimizedCompilationInfo::zone
5: v8::internal::ParseInfo::parameters_end_pos
6: uv_loop_fork
7: v8::internal::IncrementalMarking::marking_state
8: uv_dlerror
9: node::NewContext
10: node::NewIsolate
11: node::Start
12: v8::SnapshotCreator::`default constructor closure'
13: v8::internal::interpreter::BytecodeArrayRandomIterator::UpdateOffsetFromIndex
14: BaseThreadInitThunk
15: RtlUserThreadStart
Windows PowerShell[1120]: src\node_file.cc:220: Assertion `!reading_' failed.
1: node::DecodeWrite
2: node::DecodeWrite
3: uv_loop_fork
4: uv_loop_fork
5: v8::internal::FeedbackVector::New
6: v8::internal::FeedbackVector::New
7: v8::internal::FeedbackVector::New
8: v8::internal::FeedbackVector::New
9: 000000F4ECA041C1
... And More
错误通常是随机的。
我的理论是,如果客户端取消文件而没有通知服务器,则服务器会继续发送其余数据,即使客户端没有收到它。最终,客户端请求另一个文件,然后,该文件损坏与先前的文件并导致服务器崩溃。
但是我不是http2专家。我认为在发送数据时继续检查客户端是否处于活动状态会解决问题,但是我不知道如何在nodejs中执行此操作,并且我不确定这样做是否有效。
还是我的代码有问题?我复制并粘贴了http1的代码。
感谢您提供更好的提示和建议!
再次抱歉我的英语能力。...