You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
🐛 BUG: TCP Stream read() function gets stuck #2366
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'constsocket=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 behavioursocket.readable.getReader().read();// Invalid: The program got stuck here and there are no returns or error throwns
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 ?
@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.
Activity
nicolasbeauvais commentedon Jun 23, 2024
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.
read()return the full response => fineread()return the full response andread()is called a second time => stuckread()are needed to get the full response => stuckI also noticed that the object returned by the
read()method{done: false, value: 'something'}always returndone: falsewhich might be the source of the bug ?Here is a playground script exposing the bug
dom96 commentedon Jul 8, 2024
@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 aconnection: closeheader then it doesn't get stuck anymore.nicolasbeauvais commentedon Jul 11, 2024
Thank you for fixing my playground example @dom96, the
read()behaviour makes more sense now 🙇