Skip to content

Conversation

@clintonpi
Copy link

Motivation:

When an easy_handle is added to a multi_handle, the callback set for CURLOPT_CLOSESOCKETFUNCTION constructs a _MultiHandle from an unretained reference to self. This could cause a crash in URLSession if the _MultiHandle's self is deinitialised before the callback is called, and the socket will never be closed.

Partially resolves #3813

Modifications:

  • Set the CURLOPT_CLOSESOCKETFUNCTION callback to do nothing, deferring closing the socket.
  • Schedule a socket for closure in the cancellation handler of its dispatch sources.

Result:

Better management of socket lifecycle.

Testing:

Passing existing tests is sufficient.

Motivation:

When an `easy_handle` is added to a `multi_handle`, the callback set for `CURLOPT_CLOSESOCKETFUNCTION` constructs a `_MultiHandle` from an unretained reference to `self`. This could cause a crash in `URLSession` if the `_MultiHandle`'s `self` is deinitialised before the callback is called, and the socket will never be closed.

_Partially resolves #3813_

Modifications:

- Set the `CURLOPT_CLOSESOCKETFUNCTION` callback to do nothing, deferring closing the socket.
- Schedule a socket for closure in the cancellation handler of its dispatch sources.

Result:

Better management of socket lifecycle.

Testing:

Passing existing tests is sufficient.
@jrflat
Copy link
Contributor

jrflat commented Dec 9, 2025

@swift-ci please test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SR-5761] corelibs-foundation: fix concurrency/fd ownership in MultiHandle.swift

2 participants