Open lambdalisue opened 8 months ago
Thank you for opening this. This is what is happening:
closeWrite()
.conn.readable
. The behaviour of this readable is that when the underlying resource returns EOF, the resource gets closed entirely. This is good behaviour for most cases, especially in the contexts of FsFile
- more on this below.The reason that we should continue to automatically close the resource on readable streams when EOF is reached, is because it prevents you from leaking resources in the majority of usecases. An example:
Deno.serve(async () => {
const file = await Deno.open("./README.md");
return new Response(file.readable);
});
The underlying resource being closed here automatically at EOF is good behaviour - it prevents users from leaking the file resource.
However there are use cases where you may still want to write after encountering EOF - like the use case you describe here. I think for this use case, we should add an option to Deno.connect
/ Deno.open
that allows you to specify whether the resource should be closed on encountering EOF.
namespace Deno {
function open(path: string | URL, options: { preventCloseOnEOF: boolean }): Deno.FsFile;
function connect(addr: Deno.Addr, options: { preventCloseOnEOF: boolean }): Deno.TcpConn;
function connectTls(addr: Deno.Addr, options: { preventCloseOnEOF: boolean }): Deno.TlsConn;
function startTls(conn: Deno.TcpConn, options: { preventCloseOnEOF: boolean }): Deno.TlsConn;
};
Version: Deno 1.40.3
Somehow, using
streams.toText
(ReadableStream
) instead ofstreams.readAll
(Deno.Reader
) affects the behavior ofWritableStream
of aDeno.Conn
Let's me explain this step by step.
The server read data from the client first. And then send data to the client.
If I use the following code to read the data from the client, sending data to the client also success.
But with the following code, sending data to the client fails with "Bad resource ID".
The code for sending data to the client is
So not sure but just accessing
conn.readable
has some side-effects? I guess it is similar issue with https://github.com/denoland/deno/issues/15442 but I felt the situation is a bit different so I made a new one. Please close if it is duplicated issue.What I've tried to avoid the error
reader.releaseLock()
intoText
codetoArrayBuffer
instead oftoText
preventClose
,preventAbort
, andpreventCancel
forpipeTo
Additional information
With
streams.readAll
(Success)With
streams.toText
(Fail)server.ts
client.ts