Skip to content

Commit

Permalink
Remove poll watchers when closing TCP socket
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Mar 4, 2024
1 parent 5852e0c commit ef38829
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-lions-protect.md
@@ -0,0 +1,5 @@
---
"nxjs-runtime": patch
---

Remove poll watchers when closing TCP socket
13 changes: 13 additions & 0 deletions source/tcp.c
Expand Up @@ -184,12 +184,25 @@ JSValue nx_js_tcp_close(JSContext *ctx, JSValueConst this_val, int argc, JSValue
{
return JS_EXCEPTION;
}

nx_context_t* nx_ctx = JS_GetContextOpaque(ctx);
nx_watcher_t *watcher;
nx_watcher_t *twatcher;
SLIST_FOREACH_SAFE(watcher, &nx_ctx->poll.watchers_head, next, twatcher)
{
if (watcher->fd == fd) {
// TODO: reject promise for this watcher?
nx_remove_watcher(&nx_ctx->poll, watcher);
}
}

if (close(fd))
{
// TODO: Throw a regular error
JS_ThrowTypeError(ctx, strerror(errno));
return JS_EXCEPTION;
}

return JS_UNDEFINED;
}

Expand Down

0 comments on commit ef38829

Please sign in to comment.