diff --git a/quic/api/QuicTransportBase.cpp b/quic/api/QuicTransportBase.cpp index 0ccd6dac8..542228cfe 100644 --- a/quic/api/QuicTransportBase.cpp +++ b/quic/api/QuicTransportBase.cpp @@ -1142,7 +1142,7 @@ void QuicTransportBase::updateWriteLooper(bool thisIteration) { << *this; writeLooper_->run(thisIteration); if (conn_->loopDetectorCallback) { - conn_->debugState.needsWriteLoopDetect = + conn_->writeDebugState.needsWriteLoopDetect = (conn_->loopDetectorCallback != nullptr); } } else { @@ -1150,12 +1150,12 @@ void QuicTransportBase::updateWriteLooper(bool thisIteration) { << *this; writeLooper_->stop(); if (conn_->loopDetectorCallback) { - conn_->debugState.needsWriteLoopDetect = false; - conn_->debugState.currentEmptyLoopCount = 0; + conn_->writeDebugState.needsWriteLoopDetect = false; + conn_->writeDebugState.currentEmptyLoopCount = 0; } } if (conn_->loopDetectorCallback) { - conn_->debugState.writeDataReason = writeDataReason; + conn_->writeDebugState.writeDataReason = writeDataReason; } } @@ -2292,18 +2292,18 @@ void QuicTransportBase::writeSocketData() { auto packetsAfter = conn_->outstandingPackets.size(); bool packetWritten = (packetsAfter > packetsBefore); if (conn_->loopDetectorCallback && packetWritten) { - conn_->debugState.currentEmptyLoopCount = 0; + conn_->writeDebugState.currentEmptyLoopCount = 0; } else if ( - conn_->debugState.needsWriteLoopDetect && + conn_->writeDebugState.needsWriteLoopDetect && conn_->loopDetectorCallback) { // TODO: Currently we will to get some stats first. Then we may filter // out some errors here. For example, socket fail to write might be a // legit case to filter out. conn_->loopDetectorCallback->onSuspiciousWriteLoops( - ++conn_->debugState.currentEmptyLoopCount, - conn_->debugState.writeDataReason, - conn_->debugState.noWriteReason, - conn_->debugState.schedulerName); + ++conn_->writeDebugState.currentEmptyLoopCount, + conn_->writeDebugState.writeDataReason, + conn_->writeDebugState.noWriteReason, + conn_->writeDebugState.schedulerName); } // If we sent a new packet and the new packet was either the first // packet diff --git a/quic/api/QuicTransportFunctions.cpp b/quic/api/QuicTransportFunctions.cpp index b4c88f3c5..8bfb5f02c 100644 --- a/quic/api/QuicTransportFunctions.cpp +++ b/quic/api/QuicTransportFunctions.cpp @@ -911,10 +911,10 @@ uint64_t writeConnectionDataToSocket( connection.transportSettings.continueOnNetworkUnreachable); if (connection.loopDetectorCallback) { - connection.debugState.schedulerName = scheduler.name(); - connection.debugState.noWriteReason = NoWriteReason::WRITE_OK; + connection.writeDebugState.schedulerName = scheduler.name(); + connection.writeDebugState.noWriteReason = NoWriteReason::WRITE_OK; if (!scheduler.hasData()) { - connection.debugState.noWriteReason = NoWriteReason::EMPTY_SCHEDULER; + connection.writeDebugState.noWriteReason = NoWriteReason::EMPTY_SCHEDULER; } } auto writeLoopBeginTime = Clock::now(); @@ -954,7 +954,7 @@ uint64_t writeConnectionDataToSocket( if (!packet || packet->packet.frames.empty()) { ioBufBatch.flush(); if (connection.loopDetectorCallback) { - connection.debugState.noWriteReason = NoWriteReason::NO_FRAME; + connection.writeDebugState.noWriteReason = NoWriteReason::NO_FRAME; } return ioBufBatch.getPktSent(); } @@ -962,7 +962,7 @@ uint64_t writeConnectionDataToSocket( // No more space remaining. ioBufBatch.flush(); if (connection.loopDetectorCallback) { - connection.debugState.noWriteReason = NoWriteReason::NO_BODY; + connection.writeDebugState.noWriteReason = NoWriteReason::NO_BODY; } return ioBufBatch.getPktSent(); } @@ -1011,7 +1011,8 @@ uint64_t writeConnectionDataToSocket( // it is because a flush() call failed if (!ret) { if (connection.loopDetectorCallback) { - connection.debugState.noWriteReason = NoWriteReason::SOCKET_FAILURE; + connection.writeDebugState.noWriteReason = + NoWriteReason::SOCKET_FAILURE; } return ioBufBatch.getPktSent(); } diff --git a/quic/api/test/QuicTransportTest.cpp b/quic/api/test/QuicTransportTest.cpp index 3837cd35d..c62f66a86 100644 --- a/quic/api/test/QuicTransportTest.cpp +++ b/quic/api/test/QuicTransportTest.cpp @@ -1321,8 +1321,8 @@ TEST_F(QuicTransportTest, BusyWriteLoopDetection) { auto mockLoopDetectorCallback = std::make_unique(); auto rawLoopDetectorCallback = mockLoopDetectorCallback.get(); conn.loopDetectorCallback = std::move(mockLoopDetectorCallback); - ASSERT_FALSE(conn.debugState.needsWriteLoopDetect); - ASSERT_EQ(0, conn.debugState.currentEmptyLoopCount); + ASSERT_FALSE(conn.writeDebugState.needsWriteLoopDetect); + ASSERT_EQ(0, conn.writeDebugState.currentEmptyLoopCount); auto mockCongestionController = std::make_unique>(); auto rawCongestionController = mockCongestionController.get(); @@ -1332,28 +1332,29 @@ TEST_F(QuicTransportTest, BusyWriteLoopDetection) { // There should be no data to send at this point transport_->updateWriteLooper(true); - EXPECT_FALSE(conn.debugState.needsWriteLoopDetect); - EXPECT_EQ(WriteDataReason::NO_WRITE, conn.debugState.writeDataReason); - EXPECT_EQ(0, conn.debugState.currentEmptyLoopCount); + EXPECT_FALSE(conn.writeDebugState.needsWriteLoopDetect); + EXPECT_EQ(WriteDataReason::NO_WRITE, conn.writeDebugState.writeDataReason); + EXPECT_EQ(0, conn.writeDebugState.currentEmptyLoopCount); loopForWrites(); auto stream = transport_->createBidirectionalStream().value(); auto buf = buildRandomInputData(100); transport_->writeChain(stream, buf->clone(), true, false); transport_->updateWriteLooper(true); - EXPECT_TRUE(conn.debugState.needsWriteLoopDetect); - EXPECT_EQ(0, conn.debugState.currentEmptyLoopCount); - EXPECT_EQ(WriteDataReason::STREAM, conn.debugState.writeDataReason); + EXPECT_TRUE(conn.writeDebugState.needsWriteLoopDetect); + EXPECT_EQ(0, conn.writeDebugState.currentEmptyLoopCount); + EXPECT_EQ(WriteDataReason::STREAM, conn.writeDebugState.writeDataReason); EXPECT_CALL(*socket_, write(_, _)).WillOnce(Return(1000)); loopForWrites(); EXPECT_EQ(1, conn.outstandingPackets.size()); - EXPECT_EQ(0, conn.debugState.currentEmptyLoopCount); + EXPECT_EQ(0, conn.writeDebugState.currentEmptyLoopCount); // Queue a window update for a stream doesn't exist conn.streamManager->queueWindowUpdate(stream + 1); transport_->updateWriteLooper(true); EXPECT_TRUE( - WriteDataReason::STREAM_WINDOW_UPDATE == conn.debugState.writeDataReason); + WriteDataReason::STREAM_WINDOW_UPDATE == + conn.writeDebugState.writeDataReason); EXPECT_CALL(*socket_, write(_, _)).Times(0); EXPECT_CALL( *rawLoopDetectorCallback, @@ -1361,7 +1362,7 @@ TEST_F(QuicTransportTest, BusyWriteLoopDetection) { .Times(1); loopForWrites(); EXPECT_EQ(1, conn.outstandingPackets.size()); - EXPECT_EQ(1, conn.debugState.currentEmptyLoopCount); + EXPECT_EQ(1, conn.writeDebugState.currentEmptyLoopCount); transport_->close(folly::none); } diff --git a/quic/state/StateData.h b/quic/state/StateData.h index 73ee95a95..b1eaef7e6 100644 --- a/quic/state/StateData.h +++ b/quic/state/StateData.h @@ -786,7 +786,7 @@ struct QuicConnectionStateBase : public folly::DelayedDestruction { // Debug information. Currently only used to debug busy loop of Transport // WriteLooper. - struct DebugState { + struct WriteDebugState { bool needsWriteLoopDetect{false}; uint64_t currentEmptyLoopCount{0}; WriteDataReason writeDataReason{WriteDataReason::NO_WRITE}; @@ -794,7 +794,7 @@ struct QuicConnectionStateBase : public folly::DelayedDestruction { std::string schedulerName; }; - DebugState debugState; + WriteDebugState writeDebugState; std::shared_ptr loopDetectorCallback;