From 1bf30c86208b36f6c86ebef3d29ae4bcd66828c8 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Thu, 19 Apr 2018 10:08:48 +0800 Subject: [PATCH] debug: with debug build and uv, repeat some closes The closes have to complete after libuv returned to the event loop. So make sure to catch any problem that gets introduced where another close entry in the meanwhile is unsafe. https://github.com/warmcat/libwebsockets/issues/1245 --- lib/libwebsockets.c | 3 +++ lib/service.c | 10 ++++++++++ 2 files changed, 13 insertions(+) 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