summaryrefslogtreecommitdiff
path: root/ext/websocket/02_websocketstream.js
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-06-29 07:24:01 -0600
committerGitHub <noreply@github.com>2023-06-29 07:24:01 -0600
commit93b3ff017078b2c1e993457ef43af6b52e715ba6 (patch)
tree856d339ae30fef01566d5ea919d4738c1e3fa65d /ext/websocket/02_websocketstream.js
parentb6253370cc8e430c575acd3fce0da44e057eb5b9 (diff)
fix(ext/websocket): Ensure that errors are available after async response returns (#19642)
Fixes the WPT tests that test w/invalid codes. Also explicitly ignoring some h2 tests to hopefully prevent flakes. The previous changes to WebSocketStream introduced a bug where the close errors were not made available if the `pull` method was re-entrant.
Diffstat (limited to 'ext/websocket/02_websocketstream.js')
-rw-r--r--ext/websocket/02_websocketstream.js12
1 files changed, 7 insertions, 5 deletions
diff --git a/ext/websocket/02_websocketstream.js b/ext/websocket/02_websocketstream.js
index 068fa3e1b..281025289 100644
--- a/ext/websocket/02_websocketstream.js
+++ b/ext/websocket/02_websocketstream.js
@@ -242,8 +242,8 @@ class WebSocketStream {
},
});
const pull = async (controller) => {
+ // Remember that this pull method may be re-entered before it has completed
const kind = await op_ws_next_event(this[_rid]);
-
switch (kind) {
case 0:
/* string */
@@ -266,17 +266,18 @@ class WebSocketStream {
core.tryClose(this[_rid]);
break;
}
- case 4: {
+ case 1005: {
/* closed */
- this[_closed].resolve(undefined);
+ this[_closed].resolve({ code: 1005, reason: "" });
core.tryClose(this[_rid]);
break;
}
default: {
/* close */
+ const reason = op_ws_get_error(this[_rid]);
this[_closed].resolve({
code: kind,
- reason: op_ws_get_error(this[_rid]),
+ reason,
});
core.tryClose(this[_rid]);
break;
@@ -294,7 +295,8 @@ class WebSocketStream {
return pull(controller);
}
- this[_closed].resolve(op_ws_get_error(this[_rid]));
+ const error = op_ws_get_error(this[_rid]);
+ this[_closed].reject(new Error(error));
core.tryClose(this[_rid]);
}
};