commit bc6c7da176c6f6383491b72494307a3593257323
parent adcd3fe4f6c53665fa32ef76e5e53224d49f9c75
Author: Kershaw Chang <kershaw@mozilla.com>
Date: Wed, 26 Nov 2025 09:27:03 +0000
Bug 2001675 - Propagate the stream’s error code correctly, r=necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D273999
Diffstat:
2 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/netwerk/protocol/http/TLSTransportLayer.cpp b/netwerk/protocol/http/TLSTransportLayer.cpp
@@ -86,10 +86,11 @@ TLSTransportLayer::InputStreamWrapper::Read(char* buf, uint32_t count,
// If reading from the socket succeeded (NS_SUCCEEDED(mStatus)),
// but the nss layer encountered an error remember the error.
if (NS_SUCCEEDED(mStatus)) {
- mStatus = ErrorAccordingToNSPR(code);
- LOG(("TLSTransportLayer::InputStreamWrapper::Read %p nss error %" PRIx32
- ".\n",
- this, static_cast<uint32_t>(mStatus)));
+ mStatus = mTransport->mInputStatus;
+ LOG((
+ "TLSTransportLayer::InputStreamWrapper::Read %p socket error %" PRIx32
+ ".\n",
+ this, static_cast<uint32_t>(mStatus)));
}
}
@@ -129,6 +130,7 @@ TLSTransportLayer::InputStreamWrapper::CloseWithStatus(nsresult reason) {
("TLSTransportLayer::InputStreamWrapper::CloseWithStatus [this=%p "
"reason=%" PRIx32 "]\n",
this, static_cast<uint32_t>(reason)));
+ mStatus = reason;
return mSocketIn->CloseWithStatus(reason);
}
@@ -226,10 +228,8 @@ TLSTransportLayer::OutputStreamWrapper::Write(const char* buf, uint32_t count,
}
int32_t written = PR_Write(mTransport->mFD, buf, count);
- LOG(
- ("TLSTransportLayer::OutputStreamWrapper::Write %p PRWrite(%d) = %d "
- "%d\n",
- this, count, written, PR_GetError() == PR_WOULD_BLOCK_ERROR));
+ LOG(("TLSTransportLayer::OutputStreamWrapper::Write %p PRWrite(%d) = %d",
+ this, count, written));
if (written > 0) {
*countWritten = written;
@@ -245,7 +245,11 @@ TLSTransportLayer::OutputStreamWrapper::Write(const char* buf, uint32_t count,
// Writing to the socket succeeded, but failed in nss layer.
if (NS_SUCCEEDED(mStatus)) {
- mStatus = ErrorAccordingToNSPR(code);
+ mStatus = mTransport->mOutputStatus;
+ LOG(
+ ("TLSTransportLayer:::OutputStreamWrapper::Write %p socket error "
+ "%" PRIx32 " code=%d\n",
+ this, static_cast<uint32_t>(mStatus), code));
}
}
@@ -284,6 +288,7 @@ NS_IMETHODIMP
TLSTransportLayer::OutputStreamWrapper::CloseWithStatus(nsresult reason) {
LOG(("OutputStreamWrapper::CloseWithStatus [this=%p reason=%" PRIx32 "]\n",
this, static_cast<uint32_t>(reason)));
+ mStatus = reason;
return mSocketOut->CloseWithStatus(reason);
}
@@ -518,7 +523,9 @@ TLSTransportLayer::Close(nsresult aReason) {
mSocketTransport = nullptr;
}
mSocketInWrapper.AsyncWait(nullptr, 0, 0, nullptr);
+ mSocketInWrapper.CloseWithStatus(aReason);
mSocketOutWrapper.AsyncWait(nullptr, 0, 0, nullptr);
+ mSocketOutWrapper.CloseWithStatus(aReason);
if (mOwner) {
RefPtr<TLSTransportLayer> self = this;
@@ -757,9 +764,10 @@ int32_t TLSTransportLayer::OutputInternal(const char* aBuf, int32_t aAmount) {
LOG(("TLSTransportLayer::OutputInternal %p %d", this, aAmount));
uint32_t outCountWrite = 0;
- nsresult rv = mSocketOutWrapper.WriteDirectly(aBuf, aAmount, &outCountWrite);
- if (NS_FAILED(rv)) {
- if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
+ mOutputStatus =
+ mSocketOutWrapper.WriteDirectly(aBuf, aAmount, &outCountWrite);
+ if (NS_FAILED(mOutputStatus)) {
+ if (mOutputStatus == NS_BASE_STREAM_WOULD_BLOCK) {
PR_SetError(PR_WOULD_BLOCK_ERROR, 0);
} else {
PR_SetError(PR_UNKNOWN_ERROR, 0);
@@ -774,9 +782,9 @@ int32_t TLSTransportLayer::InputInternal(char* aBuf, int32_t aAmount) {
LOG(("TLSTransportLayer::InputInternal aAmount=%d\n", aAmount));
uint32_t outCountRead = 0;
- nsresult rv = mSocketInWrapper.ReadDirectly(aBuf, aAmount, &outCountRead);
- if (NS_FAILED(rv)) {
- if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
+ mInputStatus = mSocketInWrapper.ReadDirectly(aBuf, aAmount, &outCountRead);
+ if (NS_FAILED(mInputStatus)) {
+ if (mInputStatus == NS_BASE_STREAM_WOULD_BLOCK) {
PR_SetError(PR_WOULD_BLOCK_ERROR, 0);
} else {
PR_SetError(PR_UNKNOWN_ERROR, 0);
diff --git a/netwerk/protocol/http/TLSTransportLayer.h b/netwerk/protocol/http/TLSTransportLayer.h
@@ -153,6 +153,8 @@ class TLSTransportLayer final : public nsISocketTransport,
nsCOMPtr<nsIOutputStreamCallback> mOutputCallback;
PRFileDesc* mFD{nullptr};
nsCOMPtr<nsIInputStreamCallback> mOwner;
+ nsresult mOutputStatus{NS_OK};
+ nsresult mInputStatus{NS_OK};
};
} // namespace mozilla::net