diff options
| author | Garrett D'Amore <garrett@damore.org> | 2021-01-03 16:01:53 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2021-01-10 15:45:07 -0800 |
| commit | 35533f4b968fc14b80a085e0246aa3074c1dec6f (patch) | |
| tree | 937909cd8e2a1c8d5424dae13b73cfd4d893a497 /src/supplemental/websocket/websocket.c | |
| parent | 6a9bd051c439ef66cf00795b3829ca3ceece0497 (diff) | |
| download | nng-35533f4b968fc14b80a085e0246aa3074c1dec6f.tar.gz nng-35533f4b968fc14b80a085e0246aa3074c1dec6f.tar.bz2 nng-35533f4b968fc14b80a085e0246aa3074c1dec6f.zip | |
fixes #1403 http ws listeners added without a lock
Diffstat (limited to 'src/supplemental/websocket/websocket.c')
| -rw-r--r-- | src/supplemental/websocket/websocket.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/supplemental/websocket/websocket.c b/src/supplemental/websocket/websocket.c index daf1be13..416d968c 100644 --- a/src/supplemental/websocket/websocket.c +++ b/src/supplemental/websocket/websocket.c @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2019 Devolutions <info@devolutions.net> // @@ -1510,6 +1510,12 @@ ws_handler(nni_aio *aio) conn = nni_aio_get_input(aio, 2); l = nni_http_handler_get_data(h); + nni_mtx_lock(&l->mtx); + if (l->closed) { + status = NNG_HTTP_STATUS_SERVICE_UNAVAILABLE; + goto err; + } + // Now check the headers, etc. if (strcmp(nni_http_req_get_version(req), "HTTP/1.1") != 0) { status = NNG_HTTP_STATUS_HTTP_VERSION_NOT_SUPP; @@ -1609,6 +1615,7 @@ ws_handler(nni_aio *aio) if (rv != 0) { nni_http_res_free(res); nni_aio_finish_error(aio, rv); + nni_mtx_unlock(&l->mtx); return; } @@ -1625,6 +1632,7 @@ ws_handler(nni_aio *aio) nni_http_req_free(req); nni_aio_set_output(aio, 0, res); nni_aio_finish(aio, 0, 0); + nni_mtx_unlock(&l->mtx); return; } } @@ -1657,6 +1665,7 @@ ws_handler(nni_aio *aio) (void) nni_http_hijack(conn); nni_aio_set_output(aio, 0, NULL); nni_aio_finish(aio, 0, 0); + nni_mtx_unlock(&l->mtx); return; err: @@ -1666,6 +1675,7 @@ err: nni_aio_set_output(aio, 0, res); nni_aio_finish(aio, 0, 0); } + nni_mtx_unlock(&l->mtx); } static void |
