Fix process finished crash if the http reply timed out in the mean time

This commit is contained in:
Simon Stürz 2022-03-21 13:29:46 +01:00
parent 28d2f53261
commit 432130b0af

View File

@ -385,6 +385,9 @@ HttpReply *DebugServerHandler::processDebugRequest(const QString &requestPath, c
m_pingProcess->start("ping", { "-c", "4", "nymea.io" } ); m_pingProcess->start("ping", { "-c", "4", "nymea.io" } );
m_pingReply = HttpReply::createAsyncReply(); m_pingReply = HttpReply::createAsyncReply();
connect(m_pingReply, &HttpReply::finished, this, [this](){
m_pingReply = nullptr;
});
return m_pingReply; return m_pingReply;
} }
@ -400,6 +403,9 @@ HttpReply *DebugServerHandler::processDebugRequest(const QString &requestPath, c
m_digProcess->start("dig", { "nymea.io" } ); m_digProcess->start("dig", { "nymea.io" } );
m_digReply = HttpReply::createAsyncReply(); m_digReply = HttpReply::createAsyncReply();
connect(m_digReply, &HttpReply::finished, this, [this](){
m_digReply = nullptr;
});
return m_digReply; return m_digReply;
} }
@ -415,6 +421,9 @@ HttpReply *DebugServerHandler::processDebugRequest(const QString &requestPath, c
m_tracePathProcess->start("tracepath", { "nymea.io" } ); m_tracePathProcess->start("tracepath", { "nymea.io" } );
m_tracePathReply = HttpReply::createAsyncReply(); m_tracePathReply = HttpReply::createAsyncReply();
connect(m_tracePathReply, &HttpReply::finished, this, [this](){
m_tracePathProcess = nullptr;
});
return m_tracePathReply; return m_tracePathReply;
} }
@ -687,46 +696,59 @@ void DebugServerHandler::onWebsocketClientError(QAbstractSocket::SocketError err
void DebugServerHandler::onPingProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) void DebugServerHandler::onPingProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{ {
qCDebug(dcDebugServer()) << "Ping process finished" << exitCode << exitStatus; qCDebug(dcDebugServer()) << "Ping process finished" << exitCode << exitStatus;
QByteArray processOutput = m_pingProcess->readAll(); if (m_pingProcess) {
qCDebug(dcDebugServer()) << "Ping output:" << endl << qUtf8Printable(processOutput); QByteArray processOutput = m_pingProcess->readAll();
qCDebug(dcDebugServer()) << "Ping output:" << endl << qUtf8Printable(processOutput);
m_pingReply->setPayload(processOutput); if (m_pingReply) {
m_pingReply->setHttpStatusCode(HttpReply::Ok); m_pingReply->setPayload(processOutput);
m_pingReply->finished(); m_pingReply->setHttpStatusCode(HttpReply::Ok);
m_pingReply = nullptr; m_pingReply->finished();
m_pingReply = nullptr;
}
m_pingProcess->deleteLater(); m_pingProcess->deleteLater();
m_pingProcess = nullptr; m_pingProcess = nullptr;
}
} }
void DebugServerHandler::onDigProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) void DebugServerHandler::onDigProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{ {
qCDebug(dcDebugServer()) << "Dig process finished" << exitCode << exitStatus; qCDebug(dcDebugServer()) << "Dig process finished" << exitCode << exitStatus;
QByteArray processOutput = m_digProcess->readAll(); if (m_digProcess) {
qCDebug(dcDebugServer()) << "Dig output:" << endl << qUtf8Printable(processOutput); QByteArray processOutput = m_digProcess->readAll();
qCDebug(dcDebugServer()) << "Dig output:" << endl << qUtf8Printable(processOutput);
m_digReply->setPayload(processOutput); if (m_digReply) {
m_digReply->setHttpStatusCode(HttpReply::Ok); m_digReply->setPayload(processOutput);
m_digReply->finished(); m_digReply->setHttpStatusCode(HttpReply::Ok);
m_digReply = nullptr; m_digReply->finished();
m_digReply = nullptr;
}
m_digProcess->deleteLater(); m_digProcess->deleteLater();
m_digProcess = nullptr; m_digProcess = nullptr;
}
} }
void DebugServerHandler::onTracePathProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) void DebugServerHandler::onTracePathProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{ {
qCDebug(dcDebugServer()) << "Tracepath process finished" << exitCode << exitStatus; qCDebug(dcDebugServer()) << "Tracepath process finished" << exitCode << exitStatus;
QByteArray processOutput = m_tracePathProcess->readAll();
qCDebug(dcDebugServer()) << "Tracepath output:" << endl << qUtf8Printable(processOutput);
m_tracePathReply->setPayload(processOutput); if (m_tracePathProcess) {
m_tracePathReply->setHttpStatusCode(HttpReply::Ok); QByteArray processOutput = m_tracePathProcess->readAll();
m_tracePathReply->finished(); qCDebug(dcDebugServer()) << "Tracepath output:" << endl << qUtf8Printable(processOutput);
m_tracePathReply = nullptr;
m_tracePathProcess->deleteLater(); if (m_tracePathReply) {
m_tracePathProcess = nullptr; m_tracePathReply->setPayload(processOutput);
m_tracePathReply->setHttpStatusCode(HttpReply::Ok);
m_tracePathReply->finished();
m_tracePathReply = nullptr;
}
m_tracePathProcess->deleteLater();
m_tracePathProcess = nullptr;
}
} }
void DebugServerHandler::onDebugReportGeneratorFinished(bool success) void DebugServerHandler::onDebugReportGeneratorFinished(bool success)