aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-03-15 22:01:58 -0700
committerGravatar GitHub <noreply@github.com> 2023-03-15 22:01:58 -0700
commitd5ef247b3b68411980d265a812fea9c5bcc23d28 (patch)
treef0d4e5900ecffc1f20b07a5a536828a41ae8619d
parentb66df90b49c8be8b664e6d604d0fca1927aac5f5 (diff)
downloadbun-d5ef247b3b68411980d265a812fea9c5bcc23d28.tar.gz
bun-d5ef247b3b68411980d265a812fea9c5bcc23d28.tar.zst
bun-d5ef247b3b68411980d265a812fea9c5bcc23d28.zip
Fix socket tests with connection errors (#2403)
* release pending activity with connection error handler * unref poll_ref
-rw-r--r--src/bun.js/api/bun/socket.zig2
-rw-r--r--test/js/bun/net/socket.test.ts10
2 files changed, 11 insertions, 1 deletions
diff --git a/src/bun.js/api/bun/socket.zig b/src/bun.js/api/bun/socket.zig
index 0c489fa2e..bc2b65a09 100644
--- a/src/bun.js/api/bun/socket.zig
+++ b/src/bun.js/api/bun/socket.zig
@@ -1036,6 +1036,8 @@ fn NewSocket(comptime ssl: bool) type {
var promise = val.asPromise().?;
const err_ = err.toErrorInstance(globalObject);
promise.rejectOnNextTickAsHandled(globalObject, err_);
+ this.has_pending_activity.store(false, .Release);
+ this.poll_ref.unref(handlers.vm);
}
}
diff --git a/test/js/bun/net/socket.test.ts b/test/js/bun/net/socket.test.ts
index 881175b24..9ee60bc63 100644
--- a/test/js/bun/net/socket.test.ts
+++ b/test/js/bun/net/socket.test.ts
@@ -1,5 +1,5 @@
import { expect, it } from "bun:test";
-import { bunExe } from "harness";
+import { bunExe, expectObjectTypeCount } from "harness";
import { connect, spawn } from "bun";
it("should keep process alive only when active", async () => {
@@ -91,6 +91,10 @@ it("should reject on connection error, calling both connectError() and rejecting
);
});
+it("should not leak memory when connect() fails", async () => {
+ await expectObjectTypeCount("TCPSocket", 1, 100);
+});
+
// this also tests we mark the promise as handled if connectError() is called
it("should handle connection error", done => {
var data = {};
@@ -128,3 +132,7 @@ it("should handle connection error", done => {
},
});
});
+
+it("should not leak memory when connect() fails again", async () => {
+ await expectObjectTypeCount("TCPSocket", 1, 100);
+});