|
| 1 | +# GitHub Actions Memory Checking Setup |
| 2 | + |
| 3 | +This directory contains GitHub Actions workflows for comprehensive memory and thread safety testing. |
| 4 | + |
| 5 | +## Workflows |
| 6 | + |
| 7 | +### 🧵 sanitizers.yml - Memory & Thread Sanitizers (PRIMARY) |
| 8 | +**Runs:** On every push and pull request |
| 9 | +**Sanitizers Included:** |
| 10 | +- **ThreadSanitizer (TSan)** - Detects data races and thread safety issues (CRITICAL for csv-parser) |
| 11 | +- **AddressSanitizer (ASan)** - Detects memory errors: use-after-free, buffer overflows, memory leaks |
| 12 | +- **UndefinedBehaviorSanitizer (UBSan)** - Catches undefined behavior: signed overflow, type mismatches |
| 13 | + |
| 14 | +**Config:** |
| 15 | +- Runs on Ubuntu with GCC |
| 16 | +- Tests C++17 and C++20 standards |
| 17 | +- Debug builds for better diagnostics |
| 18 | +- Timeout: 20 minutes per configuration |
| 19 | +- Artifacts: Upload logs on failure |
| 20 | + |
| 21 | +**Key Features:** |
| 22 | +- Matrix testing: 3 sanitizers × 2 C++ standards = 6 parallel jobs |
| 23 | +- Fail-fast disabled to see all results |
| 24 | +- Environment variables configured for halt-on-error behavior |
| 25 | + |
| 26 | +### 💾 valgrind.yml - Valgrind Memory Profiler |
| 27 | +**Runs:** On every push and pull request |
| 28 | +**Uses:** Valgrind with full leak checking |
| 29 | + |
| 30 | +**Config:** |
| 31 | +- Runs on Ubuntu with GCC |
| 32 | +- Debug build with -O1 for balance |
| 33 | +- Excludes multi-threaded tests (Valgrind + threads = slow) |
| 34 | +- Timeout: 60 minutes (Valgrind is slower) |
| 35 | + |
| 36 | +### 🔍 codeql.yml - Static Analysis (GitHub CodeQL) |
| 37 | +**Runs:** On every push and pull request + weekly schedule |
| 38 | +**Analysis:** |
| 39 | +- Deep static analysis for security and quality issues |
| 40 | +- Integrates with GitHub Security tab |
| 41 | + |
| 42 | +## Testing Recommendations |
| 43 | + |
| 44 | +### Local Testing Before Push |
| 45 | +```bash |
| 46 | +# Test with ThreadSanitizer (most critical) |
| 47 | +cmake -B build/tsan -DCMAKE_BUILD_TYPE=Debug \ |
| 48 | + -DCMAKE_CXX_FLAGS="-fsanitize=thread -g" |
| 49 | +cmake --build build/tsan |
| 50 | +cd build/tsan && ctest --output-on-failure && cd ../.. |
| 51 | + |
| 52 | +# Test with AddressSanitizer |
| 53 | +cmake -B build/asan -DCMAKE_BUILD_TYPE=Debug \ |
| 54 | + -DCMAKE_CXX_FLAGS="-fsanitize=address -fno-omit-frame-pointer -g" |
| 55 | +cmake --build build/asan |
| 56 | +cd build/asan && ctest --output-on-failure && cd ../.. |
| 57 | +``` |
| 58 | + |
| 59 | +### CI/CD Pipeline Order |
| 60 | +1. **Primary:** ThreadSanitizer - Catches data races in threading model |
| 61 | +2. **Primary:** AddressSanitizer - Catches memory corruption |
| 62 | +3. **Secondary:** UBSanitizer - Catches subtle undefined behavior |
| 63 | +4. **Nightly:** Valgrind - Comprehensive memory profiling |
| 64 | +5. **Continuous:** CodeQL - Static analysis |
| 65 | + |
| 66 | +## Known Considerations |
| 67 | + |
| 68 | +### ThreadSanitizer (TSan) |
| 69 | +- **Why CRITICAL:** csv-parser uses worker threads + ThreadSafeDeque + double_quote_fields lazy init |
| 70 | +- May report false positives in STL (benign race detection) |
| 71 | +- Slower execution due to extra instrumentation |
| 72 | +- Catches real issues in PR #282 exception propagation and issue #278 move semantics |
| 73 | + |
| 74 | +### AddressSanitizer (ASan) |
| 75 | +- **Why Important:** Catches CSVFieldList memory issues like issue #278 |
| 76 | +- Cannot run simultaneously with TSan (different memory models) |
| 77 | +- Better performance than TSan for memory safety |
| 78 | + |
| 79 | +### Valgrind |
| 80 | +- Slower than sanitizers but more mature tool |
| 81 | +- Useful for final verification before releases |
| 82 | +- Runs on push (not PR) to avoid GitHub Actions timeout |
| 83 | + |
| 84 | +### CodeQL |
| 85 | +- No runtime overhead |
| 86 | +- Integrated into GitHub Security tab |
| 87 | +- Good for catching security issues and code quality |
| 88 | + |
| 89 | +## Interpreting Results |
| 90 | + |
| 91 | +### Sanitizer Failures |
| 92 | +Look for: |
| 93 | +``` |
| 94 | +ERROR: ThreadSanitizer: data race detected |
| 95 | +ERROR: AddressSanitizer: heap-buffer-overflow |
| 96 | +ERROR: UndefinedBehaviorSanitizer: signed integer overflow |
| 97 | +``` |
| 98 | + |
| 99 | +### Action Items |
| 100 | +1. Check artifacts uploaded on test failure |
| 101 | +2. Look at the specific sanitizer output in GitHub Actions logs |
| 102 | +3. Focus on ThreadSanitizer results first (threading complexity) |
| 103 | +4. Correlate with codebase changes to identify root cause |
| 104 | + |
| 105 | +## History |
| 106 | + |
| 107 | +- **PR #282:** ThreadSanitizer would catch exception propagation issues |
| 108 | +- **Issue #278:** AddressSanitizer catches CSVFieldList move semantics bug |
| 109 | +- **PR #237:** TSan catches double_quote_fields concurrency todo |
| 110 | +- **v2.3.0:** ThreadSafeDeque prevents std::vector reallocation race |
| 111 | + |
| 112 | +## Reference |
| 113 | + |
| 114 | +- [ThreadSanitizer Documentation](https://github.com/google/sanitizers/wiki/ThreadSanitizerCppManual) |
| 115 | +- [AddressSanitizer Documentation](https://github.com/google/sanitizers/wiki/AddressSanitizer) |
| 116 | +- [Valgrind User Manual](https://valgrind.org/docs/manual/) |
| 117 | +- [CodeQL Query Help](https://codeql.github.io/codeql-query-help/) |
0 commit comments