summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal_binding/stream_wrap.ts
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-08-11 17:27:41 +0530
committerGitHub <noreply@github.com>2023-08-11 11:57:41 +0000
commit33dc5d262288f4efae3077978f37f22338568b35 (patch)
treed4fdc4b6d9c7a6ab775754f5c1b923e5da04d7ab /ext/node/polyfills/internal_binding/stream_wrap.ts
parent2f00b0add476bb151bc3a713da165296906cfc2a (diff)
fix(node): implement TLSSocket._start (#20120)
Closes https://github.com/denoland/deno/issues/19983 Closes https://github.com/denoland/deno/issues/18303 Closes https://github.com/denoland/deno/issues/16681 Closes https://github.com/denoland/deno/issues/19978
Diffstat (limited to 'ext/node/polyfills/internal_binding/stream_wrap.ts')
-rw-r--r--ext/node/polyfills/internal_binding/stream_wrap.ts17
1 files changed, 16 insertions, 1 deletions
diff --git a/ext/node/polyfills/internal_binding/stream_wrap.ts b/ext/node/polyfills/internal_binding/stream_wrap.ts
index 528dd7c3f..66ebbe682 100644
--- a/ext/node/polyfills/internal_binding/stream_wrap.ts
+++ b/ext/node/polyfills/internal_binding/stream_wrap.ts
@@ -314,9 +314,16 @@ export class LibuvStreamWrap extends HandleWrap {
let buf = BUF;
let nread: number | null;
+ const ridBefore = this[kStreamBaseField]!.rid;
try {
nread = await this[kStreamBaseField]!.read(buf);
} catch (e) {
+ // Try to read again if the underlying stream resource
+ // changed. This can happen during TLS upgrades (eg. STARTTLS)
+ if (ridBefore != this[kStreamBaseField]!.rid) {
+ return this.#read();
+ }
+
if (
e instanceof Deno.errors.Interrupted ||
e instanceof Deno.errors.BadResource
@@ -365,15 +372,23 @@ export class LibuvStreamWrap extends HandleWrap {
async #write(req: WriteWrap<LibuvStreamWrap>, data: Uint8Array) {
const { byteLength } = data;
+ const ridBefore = this[kStreamBaseField]!.rid;
+
+ let nwritten = 0;
try {
// TODO(crowlKats): duplicate from runtime/js/13_buffer.js
- let nwritten = 0;
while (nwritten < data.length) {
nwritten += await this[kStreamBaseField]!.write(
data.subarray(nwritten),
);
}
} catch (e) {
+ // Try to read again if the underlying stream resource
+ // changed. This can happen during TLS upgrades (eg. STARTTLS)
+ if (ridBefore != this[kStreamBaseField]!.rid) {
+ return this.#write(req, data.subarray(nwritten));
+ }
+
let status: number;
// TODO(cmorten): map err to status codes