Skip to content

fix(backtest): deadlock in printDataStatistics#61

Merged
chizy7 merged 1 commit into
mainfrom
fix/backtest-printstats-deadlock
Apr 18, 2026
Merged

fix(backtest): deadlock in printDataStatistics#61
chizy7 merged 1 commit into
mainfrom
fix/backtest-printstats-deadlock

Conversation

@chizy7
Copy link
Copy Markdown
Owner

@chizy7 chizy7 commented Apr 18, 2026

HistoricalDataManager::printDataStatistics() acquires m_dataMutex then calls getStartTime()/getEndTime() which re-acquire the same non-recursive mutex, deadlocking any backtest after 'Data Points: N'.

Read m_dataPoints.front/back directly while holding the existing lock.

Summary by CodeRabbit

  • Refactor
    • Enhanced performance of data statistics reporting.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dafc4470-d312-4e1f-af6a-0335a0d4b4ae

📥 Commits

Reviewing files that changed from the base of the PR and between ddc78b3 and 452c7fa.

📒 Files selected for processing (1)
  • strategies/backtesting/BacktestEngine.cpp

📝 Walkthrough

Walkthrough

Updated HistoricalDataManager::printDataStatistics() to directly access timestamps from data points instead of calling getStartTime()/getEndTime(), eliminating redundant mutex re-locking during statistics printing.

Changes

Cohort / File(s) Summary
Mutex optimization
strategies/backtesting/BacktestEngine.cpp
Modified printDataStatistics() to compute time range using m_dataPoints.front().timestamp and m_dataPoints.back().timestamp directly instead of calling getter methods that re-lock m_dataMutex.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A tiny hop through locked-down code,
Direct access lightens the load!
No mutex calls to make anew,
Just timestamps peeking right on through. 🔓

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is brief but incomplete, missing most required template sections like Type of Change, Areas Changed, Testing, Performance Impact, Security Considerations, and Checklist. Add the missing template sections including Type of Change (Bug fix), Areas Changed (Core Engine), Testing status, Performance Impact assessment, and completed Checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately identifies the main change: fixing a deadlock issue in the printDataStatistics function during backtesting.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/backtest-printstats-deadlock

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.

@chizy7 chizy7 merged commit 211d02b into main Apr 18, 2026
14 checks passed
github-actions Bot pushed a commit that referenced this pull request Apr 19, 2026
## [1.7.1](v1.7.0...v1.7.1) (2026-04-19)

### Bug Fixes

* **backtest:** deadlock in printDataStatistics ([#61](#61)) ([211d02b](211d02b))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 1.7.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant