-
Notifications
You must be signed in to change notification settings - Fork 157
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
不停访问服务器会造成系统崩溃 #61
Comments
经测试,QFuture 不起作用,现修改成如下: 增加一个函数: void JQHttpServer::AbstractManage::handleAccepted(const QPointer< Session > &session)
} 经测试,系统已经不在崩溃,但连接多了以后,会出现主动关闭的情况 |
连接多了是多到多少,目前Qt select模型下并发能力有限,短时间内超过1000个请求就可能会漏 |
就一个连接,每秒发送一次请求,服务器就会崩溃 |
不修改源码的话,也会崩溃吗? |
不修改源码的话就会崩溃,修改后,经过测试,就不崩溃了,但存在偶尔服务器拒绝服务,直接关闭连接 |
感谢反馈 |
用定时器不停地访问服务器,会造成系统崩溃。经检查,是多线程引起的,可能会存在还在处理时,连接被关闭的情况。
修改如下:
class JQLIBRARY_EXPORT Session: public QObject 类增加一个参数:
QFuture m_workingFuc;
void JQHttpServer::AbstractManage::handleAccepted(const QPointer< Session > &session)
{
session->m_workingFuc = QtConcurrent::run( handleThreadPool_.data(), this, session {
//emit onRedReady(session);
}
然后在Session所有删除自身前,等待线程结束:
#define JQHTTPSERVER_SESSION_REPLY_PROTECTION2( functionName, ... )
if ( ioDevice_.isNull() )
{
qDebug().noquote() << QStringLiteral( "JQHttpServer::Session::" ) + functionName + ": error1";
m_workingFuc.waitForFinished();
this->deleteLater();
return VA_ARGS;
}
void JQHttpServer::Session::replyFile(const QString &filePath, const int &httpStatusCode)
{
JQHTTPSERVER_SESSION_REPLY_PROTECTION( "replyFile" )
}
void JQHttpServer::Session::replyFile(const QString &fileName, const QByteArray &fileData, const int &httpStatusCode)
{
JQHTTPSERVER_SESSION_REPLY_PROTECTION( "replyFile" )
}
void JQHttpServer::Session::replyImage(const QImage &image, const QString &format, const int &httpStatusCode)
{
JQHTTPSERVER_SESSION_REPLY_PROTECTION( "replyImage" )
}
void JQHttpServer::Session::replyImage(const QString &imageFilePath, const int &httpStatusCode)
{
JQHTTPSERVER_SESSION_REPLY_PROTECTION( "replyImage" )
}
void JQHttpServer::Session::replyBytes(const QByteArray &bytes, const QString &contentType, const int &httpStatusCode)
{
JQHTTPSERVER_SESSION_REPLY_PROTECTION( "replyBytes" )
}
void JQHttpServer::Session::replyOptions()
{
JQHTTPSERVER_SESSION_REPLY_PROTECTION( "replyOptions" )
}
void JQHttpServer::Session::inspectionBufferSetup1()
{
if ( !headerAcceptedFinished_ )
{
forever
{
static QByteArray splitFlag( "\r\n" );
// qDebug() << "JQHttpServer::Session::inspectionBuffer: error0";
m_workingFuc.waitForFinished();
this->deleteLater();
return;
}
// qDebug() << "JQHttpServer::Session::inspectionBuffer: error1";
m_workingFuc.waitForFinished();
this->deleteLater();
return;
}
// qDebug() << "JQHttpServer::Session::inspectionBuffer: error2";
m_workingFuc.waitForFinished();
this->deleteLater();
return;
}
// qDebug() << "JQHttpServer::Session::inspectionBuffer: error3:" << requestMethod_;
m_workingFuc.waitForFinished();
this->deleteLater();
return;
}
}
else if ( splitFlagIndex == 0 )
{
receiveBuffer_.remove( 0, 2 );
// qDebug() << "JQHttpServer::Session::inspectionBuffer: error4";
m_workingFuc.waitForFinished();
this->deleteLater();
return;
}
}
void JQHttpServer::Session::inspectionBufferSetup2()
{
requestBody_ += receiveBuffer_;
receiveBuffer_.clear();
}
void JQHttpServer::Session::onBytesWritten(const qint64 &written)
{
if ( this->waitWrittenByteCount_ < 0 ) { return; }
}
经过测试,不在出现系统崩溃。
The text was updated successfully, but these errors were encountered: