QGrpcHttp2Channel: add more debug logging

Easily allows to have a deeper inspection of the system by adding more
debug prints, which can be enabled with the logging category.

Pick-to: 6.10 6.9 6.8
Change-Id: I86d7f6c0c53c412a79a3d66f515fa1cd6757a023
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Dennis Oberst 2025-07-24 16:39:35 +02:00
parent f1200375f0
commit 7e06d79d6d
1 changed files with 25 additions and 2 deletions

View File

@ -501,6 +501,8 @@ void Http2Handler::attachStream(QHttp2Stream *stream_)
// In case we are Cancelled or Finished, a // In case we are Cancelled or Finished, a
// finished has been emitted already and the // finished has been emitted already and the
// Handler should get deleted here. // Handler should get deleted here.
qCDebug(lcStream, "[%p] Ignoring headers - already closed (state=%s)",
this, QDebug::toBytes(m_state).constData());
deleteLater(); deleteLater();
return; return;
} }
@ -698,6 +700,8 @@ void Http2Handler::sendInitialRequest()
connect(&m_deadlineTimer, &QTimer::timeout, this, &Http2Handler::deadlineTimeout); connect(&m_deadlineTimer, &QTimer::timeout, this, &Http2Handler::deadlineTimeout);
m_deadlineTimer.start(*deadline); m_deadlineTimer.start(*deadline);
} }
qCDebug(lcStream, "[%p] Sending initial request (deadline=%s)", this,
deadline ? qPrintable(QString::number(deadline->count()) + " ms"_L1) : "None");
} }
// The core logic for sending the already serialized data through the HTTP/2 stream. // The core logic for sending the already serialized data through the HTTP/2 stream.
@ -708,8 +712,11 @@ void Http2Handler::processQueue()
if (!m_stream) if (!m_stream)
return; return;
if (m_stream->isUploadingDATA()) if (m_stream->isUploadingDATA()) {
qCDebug(lcStream, "[%p] Stream busy uploading (queue size=%" PRIdQSIZETYPE ")", this,
m_queue.size());
return; return;
}
if (m_queue.isEmpty()) if (m_queue.isEmpty())
return; return;
@ -741,6 +748,7 @@ void Http2Handler::cancelWithStatus(const QGrpcStatus &status)
{ {
if (m_state >= State::Cancelled) if (m_state >= State::Cancelled)
return; return;
qCDebug(lcStream, "[%p] Cancelling (state=%s)", this, QDebug::toBytes(m_state).data());
m_state = State::Cancelled; m_state = State::Cancelled;
// Client cancelled the stream before the deadline exceeded. // Client cancelled the stream before the deadline exceeded.
@ -760,6 +768,8 @@ void Http2Handler::writesDone()
return; return;
m_writesDoneSent = true; m_writesDoneSent = true;
qCDebug(lcStream, "[%p] Writes done received (streamClosed=%d)", this, isStreamClosedForSending());
// Stream is already (half)closed, skip sending the DATA frame with the end-of-stream flag. // Stream is already (half)closed, skip sending the DATA frame with the end-of-stream flag.
if (isStreamClosedForSending()) if (isStreamClosedForSending())
return; return;
@ -957,7 +967,9 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QUrl &uri, QGrpcHttp2Ch
&QGrpcHttp2ChannelPrivate::handleLocalSocketError); &QGrpcHttp2ChannelPrivate::handleLocalSocketError);
m_reconnectFunction = [localSocket, this] { m_reconnectFunction = [localSocket, this] {
localSocket->connectToServer(hostUri.host() + hostUri.path()); const auto name = hostUri.host() + hostUri.path();
qCDebug(lcChannel, "[%p] Connecting to local socket at: %s", this, qPrintable(name));
localSocket->connectToServer(name);
}; };
} else } else
#endif #endif
@ -989,6 +1001,8 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QUrl &uri, QGrpcHttp2Ch
&QGrpcHttp2ChannelPrivate::handleAbstractSocketError); &QGrpcHttp2ChannelPrivate::handleAbstractSocketError);
m_reconnectFunction = [sslSocket, this] { m_reconnectFunction = [sslSocket, this] {
qCDebug(lcChannel, "[%p] Connecting to SSL endpoint at: %s:%d", this,
qPrintable(hostUri.host()), hostUri.port());
sslSocket->connectToHostEncrypted(hostUri.host(), static_cast<quint16>(hostUri.port())); sslSocket->connectToHostEncrypted(hostUri.host(), static_cast<quint16>(hostUri.port()));
}; };
} else } else
@ -1008,6 +1022,8 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QUrl &uri, QGrpcHttp2Ch
&QGrpcHttp2ChannelPrivate::handleAbstractSocketError); &QGrpcHttp2ChannelPrivate::handleAbstractSocketError);
m_reconnectFunction = [httpSocket, this] { m_reconnectFunction = [httpSocket, this] {
qCDebug(lcChannel, "[%p] Connecting to TCP endpoint at: %s:%d", this,
qPrintable(hostUri.host()), hostUri.port());
httpSocket->connectToHost(hostUri.host(), static_cast<quint16>(hostUri.port())); httpSocket->connectToHost(hostUri.host(), static_cast<quint16>(hostUri.port()));
}; };
} }
@ -1032,6 +1048,8 @@ void QGrpcHttp2ChannelPrivate::processOperation(QGrpcOperationContext *operation
// Send the finished signals asynchronously, so user connections work correctly. // Send the finished signals asynchronously, so user connections work correctly.
if (!m_socket->isWritable() && m_state == ConnectionState::Connected) { if (!m_socket->isWritable() && m_state == ConnectionState::Connected) {
qCWarning(lcChannel, "[%p] Socket not writable for operation to %s (error=%s)", this,
qPrintable(hostUri.toString()), qPrintable(m_socket->errorString()));
QTimer::singleShot(0, operationContext, QTimer::singleShot(0, operationContext,
[operationContext, err = m_socket->errorString()]() { [operationContext, err = m_socket->errorString()]() {
emit operationContext->finished({ StatusCode::Unavailable, err }); emit operationContext->finished({ StatusCode::Unavailable, err });
@ -1068,6 +1086,7 @@ void QGrpcHttp2ChannelPrivate::processOperation(QGrpcOperationContext *operation
m_reconnectFunction(); m_reconnectFunction();
} }
m_state = ConnectionState::Connecting; m_state = ConnectionState::Connecting;
qCDebug(lcChannel, "[%p] State changed to 'Connecting'. Reconnection initiated.", this);
} }
} }
@ -1092,7 +1111,10 @@ void QGrpcHttp2ChannelPrivate::createHttp2Connection()
Q_ASSERT_X(m_connection, "QGrpcHttp2ChannelPrivate", "Unable to create the HTTP/2 connection"); Q_ASSERT_X(m_connection, "QGrpcHttp2ChannelPrivate", "Unable to create the HTTP/2 connection");
QObject::connect(m_socket.get(), &QAbstractSocket::readyRead, m_connection, QObject::connect(m_socket.get(), &QAbstractSocket::readyRead, m_connection,
&QHttp2Connection::handleReadyRead); &QHttp2Connection::handleReadyRead);
m_state = ConnectionState::Connected; m_state = ConnectionState::Connected;
qCDebug(lcChannel, "[%p] Created new HTTP/2 connection to %s", this,
qPrintable(hostUri.toString()));
QObject::connect(m_connection, &QHttp2Connection::settingsFrameReceived, this, [this] { QObject::connect(m_connection, &QHttp2Connection::settingsFrameReceived, this, [this] {
if (m_state == ConnectionState::SettingsReceived) { if (m_state == ConnectionState::SettingsReceived) {
@ -1102,6 +1124,7 @@ void QGrpcHttp2ChannelPrivate::createHttp2Connection()
return; return;
} }
m_state = ConnectionState::SettingsReceived; m_state = ConnectionState::SettingsReceived;
qCDebug(lcChannel, "[%p] SETTINGS frame received. Connection ready for use.", this);
for_each_non_expired_handler([](Http2Handler *handler) { handler->sendInitialRequest(); }); for_each_non_expired_handler([](Http2Handler *handler) { handler->sendInitialRequest(); });
}); });