Skip to content

Commit 8c32fe7

Browse files
committed
fix: prevent null port from being misclassified as release error
When addressDetails.port is null, the ?? 0 coercion set releasePort to 0 (not undefined), causing the error handler to emit LoopbackPortReleaseError on port 0 instead of allowing LoopbackPortAddressUnavailableError. Only assign releasePort when the port is a valid positive number, keeping it undefined otherwise so the error handler and close callback remain consistent.
1 parent e234889 commit 8c32fe7

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

packages/shared/src/Net.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,24 +231,19 @@ export const make = (
231231
family: null,
232232
port: null,
233233
};
234-
const port = addressDetails.port ?? 0;
234+
const port =
235+
addressDetails.port !== null && addressDetails.port > 0
236+
? addressDetails.port
237+
: undefined;
235238
releasePort = port;
236239

237240
probe.close((cause) => {
238-
if (cause) {
239-
settle(
240-
Effect.fail(
241-
new LoopbackPortReleaseError({
242-
host,
243-
port,
244-
cause,
245-
}),
246-
),
247-
);
248-
return;
249-
}
250-
if (addressDetails.port !== null && addressDetails.port > 0) {
251-
settle(Effect.succeed(addressDetails.port));
241+
if (port !== undefined) {
242+
if (cause) {
243+
settle(Effect.fail(new LoopbackPortReleaseError({ host, port, cause })));
244+
return;
245+
}
246+
settle(Effect.succeed(port));
252247
return;
253248
}
254249
settle(

0 commit comments

Comments
 (0)