Bug 1831635 - Check WebTransportSessionProxyState before creating stream, r=jesup,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D178219
This commit is contained in:
Kershaw Chang 2023-05-22 09:15:26 +00:00
Родитель 58e35cde69
Коммит b7200927e2
1 изменённых файлов: 32 добавлений и 12 удалений

Просмотреть файл

@ -379,6 +379,37 @@ void WebTransportSessionProxy::DoCreateStream(
} }
LOG(("WebTransportSessionProxy::DoCreateStream %p bidi=%d", this, aBidi)); LOG(("WebTransportSessionProxy::DoCreateStream %p bidi=%d", this, aBidi));
RefPtr<Http3WebTransportSession> session = aSession;
// Having no session here means that this is called by dispatching tasks.
// The mState may be already changed, so we need to check it again.
if (!aSession) {
MutexAutoLock lock(mMutex);
switch (mState) {
case WebTransportSessionProxyState::INIT:
case WebTransportSessionProxyState::NEGOTIATING:
case WebTransportSessionProxyState::NEGOTIATING_SUCCEEDED:
MOZ_ASSERT(false, "DoCreateStream called with invalid state");
aCallback->CallOnError(NS_ERROR_UNEXPECTED);
return;
case WebTransportSessionProxyState::ACTIVE: {
session = mWebTransportSession;
} break;
case WebTransportSessionProxyState::SESSION_CLOSE_PENDING:
case WebTransportSessionProxyState::CLOSE_CALLBACK_PENDING:
case WebTransportSessionProxyState::DONE:
// Session is going to be closed.
aCallback->CallOnError(NS_ERROR_NOT_AVAILABLE);
return;
}
}
if (!session) {
MOZ_ASSERT_UNREACHABLE("This should not happen");
aCallback->CallOnError(NS_ERROR_UNEXPECTED);
return;
}
RefPtr<WebTransportStreamCallbackWrapper> wrapper(aCallback); RefPtr<WebTransportStreamCallbackWrapper> wrapper(aCallback);
auto callback = auto callback =
[wrapper{std::move(wrapper)}]( [wrapper{std::move(wrapper)}](
@ -394,18 +425,6 @@ void WebTransportSessionProxy::DoCreateStream(
wrapper->CallOnStreamReady(streamProxy); wrapper->CallOnStreamReady(streamProxy);
}; };
RefPtr<Http3WebTransportSession> session = aSession;
if (!aSession) {
MutexAutoLock lock(mMutex);
session = mWebTransportSession;
}
if (!session) {
MOZ_ASSERT(false, "This should not happen");
callback(Err(NS_ERROR_UNEXPECTED));
return;
}
if (aBidi) { if (aBidi) {
session->CreateOutgoingBidirectionalStream(std::move(callback)); session->CreateOutgoingBidirectionalStream(std::move(callback));
} else { } else {
@ -624,6 +643,7 @@ WebTransportSessionProxy::OnStopRequest(nsIRequest* aRequest,
if (!pendingCreateStreamEvents.IsEmpty()) { if (!pendingCreateStreamEvents.IsEmpty()) {
if (NS_SUCCEEDED(aStatus) && if (NS_SUCCEEDED(aStatus) &&
(mState == WebTransportSessionProxyState::DONE || (mState == WebTransportSessionProxyState::DONE ||
mState == WebTransportSessionProxyState::CLOSE_CALLBACK_PENDING ||
mState == WebTransportSessionProxyState::SESSION_CLOSE_PENDING)) { mState == WebTransportSessionProxyState::SESSION_CLOSE_PENDING)) {
aStatus = NS_ERROR_FAILURE; aStatus = NS_ERROR_FAILURE;
} }