Skip to content

Fix curl resumable epoll related crash#893

Merged
DrDet merged 1 commit intomasterfrom
dvaksman/fix-curl-resumable-sigsegv
Sep 11, 2023
Merged

Fix curl resumable epoll related crash#893
DrDet merged 1 commit intomasterfrom
dvaksman/fix-curl-resumable-sigsegv

Conversation

@DrDet
Copy link
Contributor

@DrDet DrDet commented Sep 1, 2023

Problem

Sometimes SIGSEGV is raised on production from curl_epoll_cb on accessing data from script memory.

Reason

curl_epoll_cb runs after script termination, when script memory is already freed, despite the related fd is removed from epoll on script termination.

It happens because sometimes epoll callbacks can be invoked after the related 'fd' is removed from epoll. Our net_reactor at first stores epoll events from epoll_wait, and only then runs the related callbacks (see epoll_fetch_events()), and sometimes it happens that between events fetching and processing script termination is happened.
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 in curl_epoll_cb we try to keep it simple and not to do all of this stuff.

Fixes

  • explicitly check in curl_epoll_cb that fd is still present in epoll reactor

And more general fix is in the separate PR #897: don't fetch net events right before script termination

relates to KPHP-1578

@DrDet DrDet added bug Something isn't working runtime Feature related to runtime labels Sep 1, 2023
@DrDet DrDet added this to the next milestone Sep 1, 2023
@DrDet DrDet requested a review from drdzyk September 1, 2023 14:16
@DrDet DrDet self-assigned this Sep 1, 2023
drdzyk
drdzyk previously approved these changes Sep 4, 2023
@tolk-vm tolk-vm modified the milestones: 24.08.2023, next Sep 8, 2023
@DrDet DrDet force-pushed the dvaksman/fix-curl-resumable-sigsegv branch from 8a048cd to 68c09a3 Compare September 11, 2023 16:06
@drdzyk drdzyk self-requested a review September 11, 2023 16:46
@DrDet DrDet merged commit 89c1c44 into master Sep 11, 2023
@DrDet DrDet deleted the dvaksman/fix-curl-resumable-sigsegv branch September 11, 2023 18:33
DrDet added a commit that referenced this pull request Nov 7, 2023
- don't fetch net events right before script termination (relates to #893)
- added total allocation metrics: `kphp_memory_script_allocated_total`, `kphp_memory_script_allocations_count`
- removed maximum script timeout limit
- make `disable-sql` option deprecated and turned on unless SQL port is given
astrophysik pushed a commit that referenced this pull request Nov 9, 2023
- don't fetch net events right before script termination (relates to #893)
- added total allocation metrics: `kphp_memory_script_allocated_total`, `kphp_memory_script_allocations_count`
- removed maximum script timeout limit
- make `disable-sql` option deprecated and turned on unless SQL port is given
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working runtime Feature related to runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants