Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deno v0.41.0 regression: readAllSync returns zero bytes reading from stdin #4789

Closed
srackham opened this issue Apr 16, 2020 · 5 comments · Fixed by #6161
Closed

Deno v0.41.0 regression: readAllSync returns zero bytes reading from stdin #4789

srackham opened this issue Apr 16, 2020 · 5 comments · Fixed by #6161
Labels
bug Something isn't working correctly cli related to cli/ dir public API related to "Deno" namespace in JS

Comments

@srackham
Copy link

Deno.readAllSync(Deno.stdin) always returns a zero length array, for example:

$ deno --version
deno 0.41.0
v8 8.2.308
typescript 3.8.3

$ echo Hello | deno eval "console.log(Deno.readAllSync(Deno.stdin))"
Uint8Array(0) []

I verified this behaviour on Ubuntu 18.04 and Windows 10.

The issue does does not occur in Deno v0.40.0

@ry ry added the bug Something isn't working correctly label Apr 16, 2020
@ry
Copy link
Member

ry commented Apr 16, 2020

Thanks for the report. Almost certainly introduced in #4762.

@ccheng
Copy link

ccheng commented Apr 19, 2020

hmm, this is probably related: readSync not allowed on stdin:

$ deno --version
deno 0.41.0
v8 8.2.308
typescript 3.8.3

$ deno eval "Deno.stdin.readSync(new Uint8Array(1000))"
error: Uncaught TypeError: sync read not allowed on this resource  
► $deno$/ops/dispatch_minimal.ts:63:11
    at unwrapResponse ($deno$/ops/dispatch_minimal.ts:63:11)
    at Object.sendSyncMinimal ($deno$/ops/dispatch_minimal.ts:118:10)
    at Object.readSync ($deno$/ops/io.ts:20:17)
    at File.readSync ($deno$/files.ts:101:12)

I verified this readSync and the readAllSync behaviours on Ubuntu 19.10 and Mac 10.12, and that they did not occur in Deno v0.40.0.

Although this readSync issue didn't occur in Deno v0.40.0, I was encountering a problem where if Deno.stdin.readSync was called about 55-ish times, Deno freezes using 100% CPU...

@ccheng
Copy link

ccheng commented Apr 20, 2020

So I tested in Deno v0.39.0, and found Deno.stdin.readSync works correctly.

I mentioned that in Deno v0.40.0, if Deno.stdin.readSync was called about 55-ish times, Deno freezes using 100% CPU. And in v0.41.0, it throws a Uncaught TypeError: sync read not allowed on this resource.

I'm only guessing the readSync and readAllSync issues are related. If it's not, I can open a new issue for it. Thanks!

@SyrupThinker
Copy link
Contributor

SyrupThinker commented May 18, 2020

deno/cli/js/buffer.ts

Lines 180 to 192 in 93c2164

try {
const i = this.#grow(MIN_READ);
this.#reslice(i);
const fub = new Uint8Array(this.#buf.buffer, i);
const nread = r.readSync(fub);
if (nread === null) {
return n;
}
this.#reslice(i + nread);
n += nread;
} catch (e) {
return n;
}

@bartlomieju What is the reason for suppressing exceptions here?
The intend I assume is to be able to get the result of a partial throwing read, but it
currently masks the TypeError: sync read not allowed on this resource
error when synchronously reading on stdin.

@bartlomieju
Copy link
Member

@SyrupThinker I'm not sure, please open a separate issue for that, seems like a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly cli related to cli/ dir public API related to "Deno" namespace in JS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants