Skip to content

fix: remove reference in time frame builder#4177

Merged
osbornjd merged 1 commit intosPHENIX-Collaboration:masterfrom
osbornjd:tpc_segfault
Feb 14, 2026
Merged

fix: remove reference in time frame builder#4177
osbornjd merged 1 commit intosPHENIX-Collaboration:masterfrom
osbornjd:tpc_segfault

Conversation

@osbornjd
Copy link
Contributor

@osbornjd osbornjd commented Feb 13, 2026

The TPC event combining jobs occasionally seg fault. Valgrind claimed a problem at QA histogram filling, which points back to this reference being used. Removing the reference causes valgrind to no longer indicate an invalid read, and testing on one of the files that identified this the segfault no longer occurs. This will cost some CPU performance decrease for better stability

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work for users)
  • Requiring change in macros repository (Please provide links to the macros pull request in the last section)
  • I am a member of GitHub organization of sPHENIX Collaboration, EIC, or ECCE (contact Chris Pinkenburg to join)

What kind of change does this PR introduce? (Bug fix, feature, ...)

TODOs (if applicable)

Links to other PRs in macros and calibration repositories (if applicable)

TPC Time Frame Builder: Dangling Reference Removal

Motivation and Context

This PR fixes occasional segmentation faults encountered during TPC event combining jobs. Valgrind identified an invalid memory read originating from QA histogram filling in the time frame builder. Root cause analysis traced this to a dangling reference: pkt_length was aliasing data_buffer[0], but the underlying deque was subsequently modified via pop_front() and erase() operations, invalidating the reference before it was used in QA histogram filling.

Key Changes

  • TpcTimeFrameBuilder.cc (line 716): Changed const reference to const value copy
    • Before: const uint16_t& pkt_length = data_buffer[0];
    • After: const uint16_t pkt_length = data_buffer[0];
    • Eliminates the dangling reference by creating a value copy instead of an alias to a container element
    • Container modifications (pop_front() at lines 697/709/724, erase() at line 749) can no longer invalidate the pkt_length variable
    • All downstream usage of pkt_length remains semantically identical; no logic changes

Validation and Risk Assessment

  • Stability improvement: Valgrind no longer reports the invalid memory read; a file that previously triggered a segmentation fault now processes successfully
  • Performance trade-off: Marginal CPU overhead from copying a uint16_t value is acceptable in exchange for eliminating undefined behavior
  • Risk areas:
    • Performance: Minimal overhead from value copy instead of reference binding (uint16_t = 2 bytes)
    • No reconstruction behavior changes: All QA output and physics logic remain unchanged; only memory safety is improved
    • Thread-safety: No new thread-safety concerns introduced

Notes

  • AI-generated analysis may contain inaccuracies; please review the actual code logic for validation
  • This is a surgical fix addressing a specific memory safety issue without architectural changes

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

Modified the pkt_length variable declaration in two FEE-processing code paths within TpcTimeFrameBuilder.cc from a const reference to a const value, eliminating potential dangling-reference issues when data_buffer is modified.

Changes

Cohort / File(s) Summary
Reference-to-Value Conversion
offline/framework/fun4allraw/TpcTimeFrameBuilder.cc
Changed pkt_length from const uint16_t& to const uint16_t in two FEE-processing paths to prevent dangling references when data_buffer undergoes modifications (pop/erase operations). Usage logic remains unchanged.
✨ Finishing touches
  • 📝 Generate docstrings

No actionable comments were generated in the recent review. 🎉

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sphenix-jenkins-ci
Copy link

Build & test report

Report for commit 0a41d07cf2e4fcfaa240632a2a7b4be646bbcfdc:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@osbornjd
Copy link
Contributor Author

The clang tidy warnings are benign

@osbornjd osbornjd merged commit 7255ce1 into sPHENIX-Collaboration:master Feb 14, 2026
21 of 22 checks passed
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.

1 participant

Comments