Skip to content

Commit

Permalink
fix curl resumable epoll related crash
Browse files Browse the repository at this point in the history
  • Loading branch information
DrDet committed Sep 1, 2023
1 parent 8a5a520 commit 771b6fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions runtime/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CurlRequest *>(data);
php_assert(curl_request);

Expand Down
6 changes: 5 additions & 1 deletion server/php-worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ void PhpWorker::state_run() noexcept {
tvkprintf(php_runner, 3, "PHP-worker before swap context [req_id = %016llx]\n", req_id);
php_script->iterate();
tvkprintf(php_runner, 3, "PHP-worker after swap context [req_id = %016llx]\n", req_id);;
wait(0); // check for net events
if (php_script->state != run_state_t::finished) {
// We don't need to check net events when the script is going to finish.
// Otherwise we can fetch some net events related to this script that will be processed after the script termination.
wait(0);
}
break;
}
case run_state_t::query: {
Expand Down

0 comments on commit 771b6fb

Please sign in to comment.