FairRoot icon indicating copy to clipboard operation
FairRoot copied to clipboard

fix: Handle Sink/Source ownership more properly

Open ChristianTackeGSI opened this issue 11 months ago • 2 comments

Waiting for:

  • [x] #1442

FairRootManager and FairRun both used to delete fSink and fSource. In specific situations (FairRootManager getting destructed before FairRun) this leads to a double delete!

Deprecate the old FairRootManager::Set{Source,Sink} APIs that take something like an owning pointer. Introduce new Set{Sink,Source}NonOwning internal APIs.

See: https://github.com/FairRootGroup/FairRoot/issues/1418 (see "Double deleting of file source in FairRootManager and FairRun")


Checklist:

ChristianTackeGSI avatar Jul 19 '23 21:07 ChristianTackeGSI

@YanzhaoW: This should fix the second part of #1418. Could you take a look?

ChristianTackeGSI avatar Jul 19 '23 21:07 ChristianTackeGSI

Walkthrough

Walkthrough

The updates to the FairRoot codebase focus on refining memory management and deprecating outdated methods. Changes include the removal and replacement of certain member variables and methods, adjustments in file inclusions, and enhanced handling of pointers to improve stability and maintainability.

Changes

Files Changes Summary
.../steer/FairRootManager.cxx & .h Removed fSource and fSink, updated includes, deprecated old methods, and adjusted memory handling.
.../steer/FairRun.cxx Updated copyright year, added using statements, modified pointer handling, and added deprecation warnings.

Possibly related issues

  • FairRootGroup/FairRoot#1418: The refactoring of fSource and fSink handling in FairRootManager and FairRun could address issues related to memory management and double deletion mentioned in this issue.

Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5a3fc300e62a7c0e013b7bb702410252a7e88eda and 87dd3b9c467aad9d0e99b4d5216e612929bc3e11.
Files selected for processing (3)
  • fairroot/base/steer/FairRootManager.cxx (5 hunks)
  • fairroot/base/steer/FairRootManager.h (6 hunks)
  • fairroot/base/steer/FairRun.cxx (6 hunks)
Additional comments not posted (17)
fairroot/base/steer/FairRun.cxx (8)

2-2: Updated the copyright year to include 2024.


33-35: Introduced using statements for maybe_owning_ptr and non_owning from fairroot::detail. This aligns with the changes in resource management strategy to prevent ownership issues.


90-91: Resetting fSource and fSink in FairRootManager within the destructor of FairRun to avoid dangling references. This change is crucial for ensuring that resources are managed safely without memory leaks or double deletions.


193-193: Set fRootManager->fSink to a maybe_owning_ptr with non_owning policy when a new sink is set. This ensures that FairRootManager does not own the sink, which is critical for avoiding double deletion issues.


200-200: Similar to the previous comment, this line ensures that when a temporary sink is set, it is managed as a non-owning pointer in FairRootManager.


208-208: When setting the output file, the sink is again managed as a non-owning pointer. This consistency in handling the sink across different methods is good for maintainability and avoiding ownership conflicts.


222-222: The handling of the sink when setting the output file name is consistent with other sink management changes, using maybe_owning_ptr with a non-owning policy.


261-261: Setting fRootManager->fSource to a maybe_owning_ptr with non_owning policy when a new source is set. This change is aligned with the new resource management strategy to prevent ownership issues.

fairroot/base/steer/FairRootManager.h (6)

2-2: Updated the copyright year to include 2024.


11-11: Replaced FairLogger.h with FairMemory.h to reflect changes in dependency management. Ensure that FairMemory.h provides all necessary functionality that was previously covered by FairLogger.h.


20-20: Added #include <fairlogger/Logger.h>. This inclusion is necessary for logging capabilities, which are crucial for debugging and tracking the flow of execution.


53-53: Added FairRun as a friend class to FairRootManager. This allows FairRun direct access to private members of FairRootManager, which is necessary for the changes in how sources and sinks are managed.


224-224: Deprecated the SetSource method and replaced it with a version that uses std::unique_ptr for source management. This change is part of the overall strategy to improve resource management by clearly defining ownership.


228-228: Similarly, deprecated the SetSink method and updated it to use std::unique_ptr. This ensures that the ownership of sinks is well-managed and aligns with modern C++ practices.

fairroot/base/steer/FairRootManager.cxx (3)

890-890: Consider using a more robust string comparison method.

The use of strcmp for string comparison in the GetNameFromFile function could be replaced with a more modern and less error-prone method like std::string::compare. This would enhance readability and safety.


Line range hint 69-69: Constructor initialization appears correct and well-documented.


85-85: Destructor cleanup and logging are correctly implemented.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Apr 17 '24 07:04 coderabbitai[bot]