Repository navigation
Fix data race in CachedOnDiskReadBufferFromFile::getInfoForLog - #110565
alexey-milovidov wants to merge 2 commits into
Conversation
`getInfoForLog` logged the internal state of `state->buf` (its buffer pointers and offsets: `available`, `offset`, `buffer().size` and `getFileOffsetOfBufferEnd`). For the download read type the implementation buffer is a remote file reader shared via `FileSegment::getRemoteFileReader`, which hands it out without extracting it so that an intersecting read on another thread can reuse it. `getInfoForLog` is also invoked from the `nextImplStep` scope guard after the reader has been handed off - i.e. from a thread that no longer owns the read - so reading those fields raced with the current downloader mutating them in `BufferBase::set`. The race was reported by ThreadSanitizer under the `Stateless tests (amd_tsan, s3 storage, sequential)` job (write in `BufferBase::set` from `ReadBufferFromS3::nextImpl`, previous read in `BufferBase::offset` from `getInfoForLog`), and reproduced on several unrelated pull requests. Stop logging the buffer's internal state; log only whether an implementation buffer is present, which is safe to read from any thread. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110433&sha=d88ed3ff78a877cee82661cfad68267ffb415a76&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20sequential%2C%202%2F2%29 Observed on: #110433 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [90d74c7] Summary: ✅
AI ReviewSummaryThis PR narrows Final Verdict✅ No blocking or major findings. |
|
The red on |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code |
|
Closing: this is superseded by #110154 (merged into Related: #110154 |
Closes: #110564
Related: #109203
CachedOnDiskReadBufferFromFile::getInfoForLoglogged the internal state ofstate->buf(its buffer pointers and offsets:available,offset,buffer().sizeandgetFileOffsetOfBufferEnd). For the download read type (REMOTE_FS_READ_AND_PUT_IN_CACHE) the implementation buffer is a remote file reader shared viaFileSegment::getRemoteFileReader, which hands it out without extracting it so that an intersecting read on another thread can reuse it. SincegetInfoForLogis also called from thenextImplStepscope guard after the reader has been handed off — from a thread that no longer owns the read — those reads raced with the current downloader mutating the same reader inBufferBase::set.ThreadSanitizer reported this as a data race (write in
BufferBase::setfromReadBufferFromS3::nextImpl, previous read inBufferBase::offsetfromgetInfoForLog) under theStateless tests (amd_tsan, s3 storage, sequential)job. It reproduced on several unrelated pull requests, so it is a pre-existing race inmaster.This change stops
getInfoForLogfrom reading the shared reader's internal state; it now logs only whether an implementation buffer is present, which is safe to read from any thread. There is no deterministic way to add a regression test for a timing-dependent race of this kind; the fix is covered by the existingamd_tsan (s3 storage)runs.Example CI report where it was observed: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110433&sha=d88ed3ff78a877cee82661cfad68267ffb415a76&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20sequential%2C%202%2F2%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Documentation entry for user-facing changes
🤖 Generated with Claude Code