Skip to content

Commit 0e257c8

Browse files
authored
Merge pull request #1514 from cloudflare/jsnell/catch-jsexceptionthrown-readablelockimpl
2 parents 61522bb + 8d65310 commit 0e257c8

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/workerd/api/streams/standard.c++

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,15 @@ template <typename Controller>
262262
void ReadableLockImpl<Controller>::onClose(jsg::Lock& js) {
263263
KJ_SWITCH_ONEOF(state) {
264264
KJ_CASE_ONEOF(locked, ReaderLocked) {
265-
maybeResolvePromise(js, locked.getClosedFulfiller());
265+
try {
266+
maybeResolvePromise(js, locked.getClosedFulfiller());
267+
} catch (jsg::JsExceptionThrown&) {
268+
// Resolving the promise could end up throwing an exception in some cases,
269+
// causing a jsg::JsExceptionThrown to be thrown. At this point, however,
270+
// we are already in the process of closing the stream and an error at this
271+
// point is not recoverable. Log and move on.
272+
LOG_NOSENTRY(ERROR, "Error resolving ReadableStream reader closed promise");
273+
};
266274
}
267275
KJ_CASE_ONEOF(locked, ReadableLockImpl::PipeLocked) {
268276
state.template init<Unlocked>();
@@ -276,7 +284,15 @@ template <typename Controller>
276284
void ReadableLockImpl<Controller>::onError(jsg::Lock& js, v8::Local<v8::Value> reason) {
277285
KJ_SWITCH_ONEOF(state) {
278286
KJ_CASE_ONEOF(locked, ReaderLocked) {
279-
maybeRejectPromise<void>(js, locked.getClosedFulfiller(), reason);
287+
try {
288+
maybeRejectPromise<void>(js, locked.getClosedFulfiller(), reason);
289+
} catch (jsg::JsExceptionThrown&) {
290+
// Rejecting the promise could end up throwing an exception in some cases,
291+
// causing a jsg::JsExceptionThrown to be thrown. At this point, however,
292+
// we are already in the process of closing the stream and an error at this
293+
// point is not recoverable. Log and move on.
294+
LOG_NOSENTRY(ERROR, "Error rejecting ReadableStream reader closed promise");
295+
}
280296
}
281297
KJ_CASE_ONEOF(locked, ReadableLockImpl::PipeLocked) {
282298
state.template init<Unlocked>();

0 commit comments

Comments
 (0)