mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
fix(ext/websocket): do not continue reading if socket rid closes (#21849)
Fixes https://github.com/denoland/deno/issues/21379
This commit is contained in:
parent
0bed4d3e51
commit
e1fb174f86
2 changed files with 22 additions and 8 deletions
|
@ -417,9 +417,14 @@ class WebSocket extends EventTarget {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case 0: {
|
case 0: {
|
||||||
/* string */
|
/* string */
|
||||||
|
const data = op_ws_get_buffer_as_string(rid);
|
||||||
|
if (data === undefined) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
this[_serverHandleIdleTimeout]();
|
this[_serverHandleIdleTimeout]();
|
||||||
const event = new MessageEvent("message", {
|
const event = new MessageEvent("message", {
|
||||||
data: op_ws_get_buffer_as_string(rid),
|
data,
|
||||||
origin: this[_url],
|
origin: this[_url],
|
||||||
});
|
});
|
||||||
setIsTrusted(event, true);
|
setIsTrusted(event, true);
|
||||||
|
@ -428,9 +433,14 @@ class WebSocket extends EventTarget {
|
||||||
}
|
}
|
||||||
case 1: {
|
case 1: {
|
||||||
/* binary */
|
/* binary */
|
||||||
|
const d = op_ws_get_buffer(rid);
|
||||||
|
if (d == undefined) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
this[_serverHandleIdleTimeout]();
|
this[_serverHandleIdleTimeout]();
|
||||||
// deno-lint-ignore prefer-primordials
|
// deno-lint-ignore prefer-primordials
|
||||||
const buffer = op_ws_get_buffer(rid).buffer;
|
const buffer = d.buffer;
|
||||||
let data;
|
let data;
|
||||||
if (this.binaryType === "blob") {
|
if (this.binaryType === "blob") {
|
||||||
data = new Blob([buffer]);
|
data = new Blob([buffer]);
|
||||||
|
|
|
@ -703,9 +703,11 @@ pub async fn op_ws_close(
|
||||||
pub fn op_ws_get_buffer(
|
pub fn op_ws_get_buffer(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
#[smi] rid: ResourceId,
|
#[smi] rid: ResourceId,
|
||||||
) -> Result<ToJsBuffer, AnyError> {
|
) -> Option<ToJsBuffer> {
|
||||||
let resource = state.resource_table.get::<ServerWebSocket>(rid)?;
|
let Ok(resource) = state.resource_table.get::<ServerWebSocket>(rid) else {
|
||||||
Ok(resource.buffer.take().unwrap().into())
|
return None;
|
||||||
|
};
|
||||||
|
resource.buffer.take().map(ToJsBuffer::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op2]
|
#[op2]
|
||||||
|
@ -713,9 +715,11 @@ pub fn op_ws_get_buffer(
|
||||||
pub fn op_ws_get_buffer_as_string(
|
pub fn op_ws_get_buffer_as_string(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
#[smi] rid: ResourceId,
|
#[smi] rid: ResourceId,
|
||||||
) -> Result<String, AnyError> {
|
) -> Option<String> {
|
||||||
let resource = state.resource_table.get::<ServerWebSocket>(rid)?;
|
let Ok(resource) = state.resource_table.get::<ServerWebSocket>(rid) else {
|
||||||
Ok(resource.string.take().unwrap())
|
return None;
|
||||||
|
};
|
||||||
|
resource.string.take()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op2]
|
#[op2]
|
||||||
|
|
Loading…
Reference in a new issue