From 68c09a3ae84efb8297ea1d8f0fd070f0bcd40212 Mon Sep 17 00:00:00 2001 From: Denis Vaksman Date: Fri, 1 Sep 2023 16:50:47 +0300 Subject: [PATCH] fix curl resumable epoll related crash --- runtime/curl.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/runtime/curl.cpp b/runtime/curl.cpp index 5017b244c0..60f6316e24 100644 --- a/runtime/curl.cpp +++ b/runtime/curl.cpp @@ -1129,6 +1129,15 @@ void CurlRequest::detach_multi_and_easy_handles() const noexcept { } static int curl_epoll_cb(int fd, void *data, event_t *ev) { + // Sometimes epoll callbacks can be invoked AFTER the related 'fd' is removed from epoll. + // It happens because our net_reactor at first stores epoll events from epoll_wait, and only then runs related callbacks (see epoll_fetch_events()) + // Usually this situation is handled via some additional connection flags (conn_expect_query, C_WANTRD etc.) + // in callbacks like `server_read_write_gateway` and related. + // But here we try to keep it simple and not to do all of this stuff. + // So we need to check explicitly that this fd is still present in epoll reactor: + if (!(ev->state & EVT_IN_EPOLL)) { + return 0; + } auto *curl_request = static_cast(data); php_assert(curl_request);