Skip to content

Commit

Permalink
destroy socket after a timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKhanj committed Dec 22, 2023
1 parent 6077bd8 commit 05ffd6d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moxyjs",
"version": "0.0.7",
"version": "0.0.8",
"description": "Distributed transparent proxy with traffic control facilities",
"author": "Pooyan Khanjankhani <[email protected]>",
"license": "MIT",
Expand Down
12 changes: 12 additions & 0 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class TcpProxy implements Proxy {
clientSocket.on("close", () => {
this.logger.log("Client disconnected");
forwardSocket.end();
setTimeout(() => {
if (forwardSocket.destroyed) return;
forwardSocket.destroy();
}, 10_000);
});

clientSocket.on("error", (err) => {
Expand All @@ -104,6 +108,10 @@ class TcpProxy implements Proxy {
} else {
this.logger.error("Local socket error:", err);
clientSocket.end();
setTimeout(() => {
if (clientSocket.destroyed) return;
clientSocket.destroy();
}, 10_000);
}
});

Expand All @@ -114,6 +122,10 @@ class TcpProxy implements Proxy {
forwardSocket.on("error", (err) => {
this.logger.error(`Forward socket error: ${err}`);
clientSocket.end();
setTimeout(() => {
if (clientSocket.destroyed) return;
clientSocket.destroy();
}, 10_000);
});
}

Expand Down

0 comments on commit 05ffd6d

Please sign in to comment.