Skip to content

🐛 BUG: TCP Stream read() function gets stuck #2366

Closed

Description

@JamesDelfini

Which Cloudflare product(s) does this pertain to?

Workers for Platforms, Workers Runtime

What version(s) of the tool(s) are you using?

3.18.0 [Wrangler]

What version of Node are you using?

v20.11.0

What operating system and version are you using?

Windows 11

Describe the Bug

After performing a write operation and expecting a response, the issue arises when calling read() again. It gets stuck in this scenario.

import { connect } from 'cloudflare:sockets'

const socket = connect(...);

socket.writable.getWriter().write(...);
const { value: bytesRead } = socket.readable.getReader().read(); // Valid: Expected a response from the server
// Tries to read again to reproduce the behaviour
socket.readable.getReader().read(); // Invalid: The program got stuck here and there are no returns or error throwns

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

Activity

  1. added
    bug
    on Jan 31, 2024
  2. nicolasbeauvais commented on Jun 23, 2024

    @nicolasbeauvais

    Hello,

    I experienced the same bug, the read method work as expected if a single read is enough to get the full socket response, but if the method is called more than once the script will get stuck.

    • The first read() return the full response => fine
    • The first read() return the full response and read() is called a second time => stuck
    • Multiple read() are needed to get the full response => stuck

    I also noticed that the object returned by the read() method {done: false, value: 'something'} always return done: false which might be the source of the bug ?

    Here is a playground script exposing the bug

  3. dom96 commented on Jul 8, 2024

    @dom96
    Contributor

    @nicolasbeauvais why do you expect it to return done: true? In your example the server keeps the connection open, so the socket isn't closed immediately after the data is sent. If you add a connection: close header then it doesn't get stuck anymore.

  4. nicolasbeauvais commented on Jul 11, 2024

    @nicolasbeauvais

    Thank you for fixing my playground example @dom96, the read() behaviour makes more sense now 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions