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

Hang in Deno.core.read #817

Open
bartlomieju opened this issue Jul 10, 2024 · 1 comment
Open

Hang in Deno.core.read #817

bartlomieju opened this issue Jul 10, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@bartlomieju
Copy link
Member

bartlomieju commented Jul 10, 2024

Yep, the following test reproduces the issue: read() works once then hangs on the next. Run cargo test resource_test -- --nocapture against deno_core's testing crate after adding this test to reproduce.

test(async function testPipeLargeRead() {
  const [p1, p2] = op_pipe_create()
  const bufferSize = 65536
  const maxChunkSize = 1024
  const inBuffer = new Uint8Array(bufferSize)
  inBuffer[0] = 1
  assertEquals(maxChunkSize, await Deno.core.write(p1, inBuffer))
  const buf = new Uint8Array(1024)
  for (
    let chunkIndex = 0;
    chunkIndex <= bufferSize / maxChunkSize;
    chunkIndex++
  ) {
    console.log('trying read')
    assertEquals(maxChunkSize, await Deno.core.read(p2, buf))
    console.log('did read')
    // assertArrayEquals(buf.subarray(0), [i])
  }
})

You'll see this in the console:

...
trying read
did read
trying read

then the test doesn't even complete.

Originally posted by @aunyks in denoland/deno#22767 (comment)

@bartlomieju bartlomieju added the bug Something isn't working label Jul 10, 2024
@aunyks
Copy link

aunyks commented Jul 10, 2024

The program hangs on resource.read_byob(view).await which, in the above case, uses the PipeResource implementation where (thankfully) risk was acknowledged:

async {
    let mut lock = RcRef::map(self, |this| &this.rx).borrow_mut().await;
    // Note that we're holding a slice across an await point, so this code is very much not safe
    let res = lock.read(&mut buf).await?;
    Ok((res, buf))
  }
  .boxed_local()

It's worth checking whether this can be reproduced with other Resource implementers, but I'll leave that to someone who knows more about these internals than myself!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants