Skip to content

Commit

Permalink
fix: handle EAGAIN reading from TCP connection (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
rojvv authored Jun 6, 2024
1 parent df64a4d commit f4ec4e6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/shim-deno/src/deno/internal/Conn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
///<reference path="../stable/lib.deno.d.ts" />

import { Socket } from "net";
import { once } from "events";

import { FsFile } from "../stable/classes/FsFile.js";

Expand Down Expand Up @@ -40,6 +41,21 @@ export class Conn extends FsFile implements Deno.Conn {
unref(): void {
this.#socket.unref();
}

async read(p: Uint8Array): Promise<number | null> {
try {
return await super.read(p);
} catch (error) {
if (
!(error instanceof Error && "code" in error &&
error.code == "EAGAIN")
) {
throw error;
}
}
await once(this.#socket, "readable");
return await super.read(p);
}
}

export class TlsConn extends Conn implements Deno.TlsConn {
Expand Down

0 comments on commit f4ec4e6

Please sign in to comment.