diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index fe2c5aab..b35ccdcb 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -641,6 +641,9 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, const char * wsi->http.fop_fd != NULL) lws_vfs_file_close(&wsi->http.fop_fd); + if (lwsi_state(wsi) == LRS_DEAD_SOCKET) + return; + if (wsi->socket_is_permanently_unusable || reason == LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY || lwsi_state(wsi) == LRS_SHUTDOWN) diff --git a/lib/service.c b/lib/service.c index 3468c970..dd3ef3b9 100644 --- a/lib/service.c +++ b/lib/service.c @@ -868,6 +868,16 @@ close_and_handled: lwsl_debug("%p: Close and handled\n", wsi); lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "close_and_handled"); +#if defined(_DEBUG) + /* + * confirm close has no problem being called again while + * it waits for libuv service to complete the first async + * close + */ + if (LWS_LIBUV_ENABLED(context)) + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, + "close_and_handled uv repeat test"); +#endif /* * pollfd may point to something else after the close * due to pollfd swapping scheme on delete on some platforms