Skip to content

Commit

Permalink
websocket: stop trying to accept once we're closed
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Dec 16, 2024
1 parent 1928588 commit 7c51e7b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/sp/transport/ws/websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct ws_listener {
nni_listener *nlistener;
nni_list wait_pipes;
bool started;
bool closed;
};

struct ws_pipe {
Expand Down Expand Up @@ -452,11 +453,16 @@ wstran_listener_close(void *arg)
ws_listener *l = arg;
ws_pipe *p;

nni_aio_close(&l->accaio);
NNI_LIST_FOREACH (&l->wait_pipes, p) {
nni_pipe_close(p->npipe);
nni_mtx_lock(&l->mtx);
if (!l->closed) {
l->closed = true;
nni_aio_close(&l->accaio);
NNI_LIST_FOREACH (&l->wait_pipes, p) {
nni_pipe_close(p->npipe);
}
nng_stream_listener_close(l->listener);
}
nng_stream_listener_close(l->listener);
nni_mtx_unlock(&l->mtx);
}

static void
Expand Down Expand Up @@ -515,7 +521,9 @@ wstran_accept_cb(void *arg)
nni_aio_list_remove(uaio);
nni_aio_finish_error(uaio, rv);
}
nng_stream_listener_accept(l->listener, aaio);
if (rv != NNG_ECLOSED) {
nng_stream_listener_accept(l->listener, aaio);
}
nni_mtx_unlock(&l->mtx);
}

Expand Down

0 comments on commit 7c51e7b

Please sign in to comment.