1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-08 09:42:06 +03:00

Check read callback for nullptr.

Summary: It's legit to set this to nullptr before the callback is removed.

Reviewed By: yangchi, lnicco

Differential Revision: D26582589

fbshipit-source-id: 0119e06e6e5347a9080dc5a814551e7b44d64c74
This commit is contained in:
Matt Joras
2021-02-22 12:51:03 -08:00
committed by Facebook GitHub Bot
parent 3ee0eb319f
commit 1b86b23d65
2 changed files with 12 additions and 1 deletions

View File

@@ -2699,7 +2699,8 @@ void QuicTransportBase::resetNonControlStreams(
} }
if (isReceivingStream(conn_->nodeType, id) || isBidirectionalStream(id)) { if (isReceivingStream(conn_->nodeType, id) || isBidirectionalStream(id)) {
auto readCallbackIt = readCallbacks_.find(id); auto readCallbackIt = readCallbacks_.find(id);
if (readCallbackIt != readCallbacks_.end()) { if (readCallbackIt != readCallbacks_.end() &&
readCallbackIt->second.readCb) {
readCallbackIt->second.readCb->readError(id, {error, errorMsg}); readCallbackIt->second.readCb->readError(id, {error, errorMsg});
} }
if (conn_->partialReliabilityEnabled) { if (conn_->partialReliabilityEnabled) {

View File

@@ -2273,6 +2273,16 @@ TEST_F(QuicTransportImplTest, ResetAllNonControlStreams) {
transport->notifyPendingWriteOnStream(stream3, &wcb3); transport->notifyPendingWriteOnStream(stream3, &wcb3);
EXPECT_CALL(wcb3, onStreamWriteError(stream3, _)).Times(1); EXPECT_CALL(wcb3, onStreamWriteError(stream3, _)).Times(1);
auto stream4 = transport->createBidirectionalStream().value();
NiceMock<MockWriteCallback> wcb4;
NiceMock<MockReadCallback> rcb4;
EXPECT_CALL(wcb4, onStreamWriteError(stream4, _))
.WillOnce(Invoke(
[&](auto, auto) { transport->setReadCallback(stream4, nullptr); }));
EXPECT_CALL(rcb4, readError(_, _)).Times(0);
transport->notifyPendingWriteOnStream(stream4, &wcb4);
transport->setReadCallback(stream4, &rcb4);
transport->resetNonControlStreams( transport->resetNonControlStreams(
GenericApplicationErrorCode::UNKNOWN, "bye bye"); GenericApplicationErrorCode::UNKNOWN, "bye bye");
evb->loopOnce(); evb->loopOnce();