From: Piyush Shah Date: Tue, 6 Aug 2019 14:00:58 +0000 (+0530) Subject: httpd_sess_close: Check for session validity before closing X-Git-Tag: v4.1-dev~15^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c93cab858ef0ece164312c9973c582e76c5a8c63;p=esp-idf httpd_sess_close: Check for session validity before closing If httpd_sess_trigger_close() gets called twice for the same socket, the first httpd_sess_close() cb closes the correct socket, but the second invocation closes the wrong socket which was just accepted and added to the socket db. Checking for the lru counter will help identify this as the counter is set only for requests actually served. --- diff --git a/components/esp_http_server/src/httpd_sess.c b/components/esp_http_server/src/httpd_sess.c index 8109475b4c..9deb6df2fe 100644 --- a/components/esp_http_server/src/httpd_sess.c +++ b/components/esp_http_server/src/httpd_sess.c @@ -378,6 +378,10 @@ static void httpd_sess_close(void *arg) { struct sock_db *sock_db = (struct sock_db *)arg; if (sock_db) { + if (sock_db->lru_counter == 0) { + ESP_LOGD(TAG, "Skipping session close for %d as it seems to be a race condition", sock_db->fd); + return; + } int fd = sock_db->fd; struct httpd_data *hd = (struct httpd_data *) sock_db->handle; httpd_sess_delete(hd, fd);