Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix socket tests with connection errors #2403

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/bun.js/api/bun/socket.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
10 changes: 9 additions & 1 deletion test/js/bun/net/socket.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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);
});