Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core-clp: Add class to encapsulate libcurl's global resource management. #461

Merged
merged 10 commits into from
Jul 26, 2024

Conversation

LinZhihao-723
Copy link
Member

Description

Before this PR, we reply on static methods clp::NetworkReader::init/deinit to initialize libcurl global resources. However, there are downsides of the current implementation:

  1. Curl resource management should not be specific to a particular application of libcurl; there should be a dedicated approach, instead of being a part of clp::NetworkReader
  2. The current way of doing init/deinit is just a wrapper to libcurl's C style resource management. It has nothing guaranteed about the object life cycle. This is the root cause of some of the workflow failure, such as this one: https://github.com/y-scope/clp/actions/runs/9613911655/job/26517641592, where the global deinit happens before clp::NetworkReader instance gets out of its life cycle.

This PR introduces a specialized class clp::CurlGlobalInstance for managing curl resources using the RAII pattern. Similar to mongodb, users must create an instance of a specific class to initialize the resources. Resource deallocation occurs automatically when the object is destroyed. To manage multiple instances, a thread-safe static reference count is used to track all active instances. This prevents double-initialization and ensures that global resources are not deallocated while they are still needed by other instances.

Validation performed

  1. Ensure the code gets built properly without linter errors
  2. Ensure clp::NetworkReader works as expected after switching to this new class

@kirkrodrigues kirkrodrigues requested a review from haiqi96 June 25, 2024 15:03
haiqi96
haiqi96 previously approved these changes Jun 26, 2024
Copy link
Contributor

@haiqi96 haiqi96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, @kirkrodrigues you can review the rest

components/core/src/clp/CurlGlobalInstance.cpp Outdated Show resolved Hide resolved
components/core/src/clp/CurlGlobalInstance.cpp Outdated Show resolved Hide resolved
components/core/src/clp/CurlGlobalInstance.cpp Outdated Show resolved Hide resolved
components/core/src/clp/CurlGlobalInstance.hpp Outdated Show resolved Hide resolved
components/core/src/clp/CurlGlobalInstance.hpp Outdated Show resolved Hide resolved
components/core/src/clp/CurlGlobalInstance.cpp Outdated Show resolved Hide resolved
components/core/src/clp/NetworkReader.hpp Outdated Show resolved Hide resolved
components/core/tests/test-NetworkReader.cpp Outdated Show resolved Hide resolved
components/core/tests/test-NetworkReader.cpp Outdated Show resolved Hide resolved
Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>
Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>
Copy link
Member

@kirkrodrigues kirkrodrigues left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the PR title, how about:

core-clp: Add class to encapsulate libcurl's global resource management.

@LinZhihao-723 LinZhihao-723 changed the title core-clp: Add support for appropriate libcurl global resource management. core-clp: Add class to encapsulate libcurl's global resource management. Jul 26, 2024
@LinZhihao-723 LinZhihao-723 changed the title core-clp: Add class to encapsulate libcurl's global resource management. core-clp: Add class to encapsulate libcurl's global resource management. Jul 26, 2024
@LinZhihao-723 LinZhihao-723 merged commit 0837494 into y-scope:main Jul 26, 2024
13 checks passed
jackluo923 pushed a commit to jackluo923/clp that referenced this pull request Dec 4, 2024
…ment. (y-scope#461)

Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com>
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.

3 participants