summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-10-21 23:48:32 +0000
committerMoonchild <moonchild@palemoon.org>2020-10-21 23:48:32 +0000
commit33a402947c28b35c55fae782be3a45bafa97d293 (patch)
tree10cadfe13c0e38c6c14f33887a580eef3e51d322
parent3e59623312828f0730bfd46e745567455d56048e (diff)
downloaduxp-33a402947c28b35c55fae782be3a45bafa97d293.tar.gz
[DOM Fetch] Detect broken pipes and propagate that write error to the caller.
-rw-r--r--dom/fetch/FetchDriver.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp
index d18db2834b..79bd5a0e39 100644
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -771,6 +771,17 @@ FetchDriver::OnDataAvailable(nsIRequest* aRequest,
nsresult rv = aInputStream->ReadSegments(NS_CopySegmentToStream,
mPipeOutputStream,
aCount, &aRead);
+
+ // If no data was read, it's possible the output stream is closed but the
+ // ReadSegments call followed its contract of returning NS_OK despite write
+ // errors. Unfortunately, nsIOutputStream has an ill-conceived contract when
+ // taken together with ReadSegments' contract, because the pipe will just
+ // NS_OK if we try and invoke its Write* functions ourselves with a 0 count.
+ // So we must just assume the pipe is broken.
+ if (aRead == 0 && aCount != 0) {
+ return NS_BASE_STREAM_CLOSED;
+ }
+
return rv;
}