Skip to content

Commit bd03673

Browse files
bartlomiejuclaude
andauthored
refactor: remove _readWithCancelHandle from Stdin (#33222)
Remove the `_readWithCancelHandle` mechanism -- a cancel-aware read path for stdin used by `stream_wrap.ts`. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 301e224 commit bd03673

3 files changed

Lines changed: 2 additions & 102 deletions

File tree

ext/io/12_io.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,14 @@
55
// Thank you! We love Go! <3
66

77
import { core, primordials } from "ext:core/mod.js";
8-
import {
9-
op_read_create_cancel_handle,
10-
op_read_with_cancel_handle,
11-
op_set_raw,
12-
} from "ext:core/ops";
8+
import { op_set_raw } from "ext:core/ops";
139
const {
1410
Uint8Array,
1511
ArrayPrototypePush,
1612
Symbol,
1713
TypedArrayPrototypeSubarray,
1814
TypedArrayPrototypeSet,
1915
TypedArrayPrototypeGetByteLength,
20-
PromisePrototypeThen,
2116
} = primordials;
2217

2318
import {
@@ -116,8 +111,6 @@ const STDERR_RID = 2;
116111
const REF = Symbol("REF");
117112
const UNREF = Symbol("UNREF");
118113

119-
const _readWithCancelHandle = Symbol("_readWithCancelHandle");
120-
121114
class Stdin {
122115
#rid = STDIN_RID;
123116
#ref = true;
@@ -141,22 +134,6 @@ class Stdin {
141134
return nread === 0 ? null : nread;
142135
}
143136

144-
[_readWithCancelHandle](p) {
145-
const handle = op_read_create_cancel_handle();
146-
if (p.length === 0) return { cancelHandle: handle, nread: 0 };
147-
this.#opPromise = op_read_with_cancel_handle(this.#rid, handle, p);
148-
if (!this.#ref) {
149-
core.unrefOpPromise(this.#opPromise);
150-
}
151-
return {
152-
cancelHandle: handle,
153-
nread: PromisePrototypeThen(
154-
this.#opPromise,
155-
(nread) => nread === 0 ? null : nread,
156-
),
157-
};
158-
}
159-
160137
readSync(p) {
161138
return readSync(this.#rid, p);
162139
}
@@ -271,7 +248,6 @@ const stdout = new Stdout();
271248
const stderr = new Stderr();
272249

273250
export {
274-
_readWithCancelHandle,
275251
read,
276252
readAll,
277253
readAllSync,

ext/io/lib.rs

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ use deno_core::AsyncRefCell;
2626
use deno_core::AsyncResult;
2727
use deno_core::BufMutView;
2828
use deno_core::BufView;
29-
use deno_core::CancelFuture;
3029
use deno_core::CancelHandle;
3130
use deno_core::CancelTryFuture;
32-
use deno_core::JsBuffer;
3331
use deno_core::OpState;
3432
use deno_core::RcRef;
3533
use deno_core::Resource;
@@ -212,10 +210,6 @@ fn stdio_fd(fd: i32) -> StdFile {
212210

213211
deno_core::extension!(deno_io,
214212
deps = [ deno_web ],
215-
ops = [
216-
op_read_with_cancel_handle,
217-
op_read_create_cancel_handle,
218-
],
219213
esm = [ "12_io.js" ],
220214
options = {
221215
stdio: Option<Stdio>,
@@ -1341,65 +1335,6 @@ impl crate::fs::File for StdFileResourceInner {
13411335
}
13421336
}
13431337

1344-
pub struct ReadCancelResource(Rc<CancelHandle>);
1345-
1346-
impl ReadCancelResource {
1347-
pub fn cancel_handle(&self) -> Rc<CancelHandle> {
1348-
self.0.clone()
1349-
}
1350-
}
1351-
1352-
impl Resource for ReadCancelResource {
1353-
fn name(&self) -> Cow<'_, str> {
1354-
"readCancel".into()
1355-
}
1356-
1357-
fn close(self: Rc<Self>) {
1358-
self.0.cancel();
1359-
}
1360-
}
1361-
1362-
#[op2(fast)]
1363-
#[smi]
1364-
pub fn op_read_create_cancel_handle(state: &mut OpState) -> u32 {
1365-
state
1366-
.resource_table
1367-
.add(ReadCancelResource(CancelHandle::new_rc()))
1368-
}
1369-
1370-
#[op2]
1371-
pub async fn op_read_with_cancel_handle(
1372-
state: Rc<RefCell<OpState>>,
1373-
#[smi] rid: u32,
1374-
#[smi] cancel_handle: u32,
1375-
#[buffer] buf: JsBuffer,
1376-
) -> Result<u32, JsErrorBox> {
1377-
let (fut, cancel_rc) = {
1378-
let state = state.borrow();
1379-
let cancel_handle = state
1380-
.resource_table
1381-
.get::<ReadCancelResource>(cancel_handle)
1382-
.unwrap()
1383-
.0
1384-
.clone();
1385-
1386-
(
1387-
FileResource::with_file(&state, rid, |file| {
1388-
let view = BufMutView::from(buf);
1389-
Ok(file.read_byob(view))
1390-
}),
1391-
cancel_handle,
1392-
)
1393-
};
1394-
1395-
fut?
1396-
.or_cancel(cancel_rc)
1397-
.await
1398-
.map_err(|_| JsErrorBox::generic("cancelled"))?
1399-
.map(|(n, _)| n as u32)
1400-
.map_err(JsErrorBox::from_err)
1401-
}
1402-
14031338
// override op_print to use the stdout and stderr in the resource table
14041339
#[op2(fast)]
14051340
pub fn op_print(

ext/node/polyfills/internal_binding/stream_wrap.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import {
5353
providerType,
5454
} from "ext:deno_node/internal_binding/async_wrap.ts";
5555
import { codeMap } from "ext:deno_node/internal_binding/uv.ts";
56-
import { _readWithCancelHandle } from "ext:deno_io/12_io.js";
5756
import { NodeTypeError } from "ext:deno_node/internal/errors.ts";
5857

5958
export const kUseNativeWrap = Symbol("useNativeWrap");
@@ -385,17 +384,7 @@ export class LibuvStreamWrap extends HandleWrap {
385384

386385
const ridBefore = this[kStreamBaseField]![internalRidSymbol];
387386
try {
388-
if (this[kStreamBaseField]![_readWithCancelHandle]) {
389-
const { cancelHandle, nread: p } = this[kStreamBaseField]!
390-
[_readWithCancelHandle](buf);
391-
if (cancelHandle) {
392-
this.cancelHandle = cancelHandle;
393-
}
394-
395-
nread = await p;
396-
} else {
397-
nread = await this[kStreamBaseField]!.read(buf);
398-
}
387+
nread = await this[kStreamBaseField]!.read(buf);
399388
} catch (e) {
400389
// Try to read again if the underlying stream resource
401390
// changed. This can happen during TLS upgrades (eg. STARTTLS)

0 commit comments

Comments
 (0)