Skip to content

Fix crash in log file rotation when the process has no free file descriptors - #130517

Merged
CheSema merged 4 commits into
masterfrom
fix-file-channel-rotation-emfile
Nov 10, 2026
Merged

CheSema merged 4 commits into
masterfrom
fix-file-channel-rotation-emfile

Conversation

@CheSema

@CheSema CheSema commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

ArchiveStrategy::archive deletes the current LogFile before it renames the files and opens a new one. When the process has no free file descriptors, that open throws, the fallback newLogFile in Poco::FileChannel throws too, and _pFile keeps pointing to the deleted object. The next log message reads freed memory in LogFileImpl::sizeImpl, and the server crashes with SIGSEGV. Now _pFile is reset before archive. While descriptors are exhausted, the log file loses messages, and logging recovers when descriptors are free again.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a server crash (SIGSEGV in Poco::LogFileImpl::sizeImpl) when the log file was rotated while the process had no free file descriptors.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/130517]

Version info

  • Merged into: 26.11.1.1889-master (included in 26.11 and later)

`ArchiveStrategy::archive` deletes the current `LogFile` before it opens the new one. When
that open and the fallback `newLogFile` both failed with EMFILE, `FileChannel::_pFile` kept
pointing to the deleted object, and the next message crashed in `LogFileImpl::sizeImpl`.

Closes: ClickHouse/clickhouse-core-incidents#1699
@clickhouse-gh

clickhouse-gh Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2e68ea5]

Summary: ✅


AI Review

Summary

The PR prevents FileChannel::_pFile from retaining a deleted LogFile when rotation and reopening both fail. The shared helper covers rotation during logging and opening, and the regression test exercises descriptor exhaustion, repeated failure, and recovery. No actionable findings.

Missing context / blind spots
  • ⚠️ The regression test was not executed locally because this checkout has no build directory or unit-test binary. The current CI report has no completed unit-test results yet; a passing FileChannelRotation.NoFreeDescriptorsDuringRotation result would close this runtime validation gap.
Final Verdict

✅ Approve — no correctness or safety issues found in the current diff.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Nov 10, 2026
@clickhouse-gh clickhouse-gh Bot added the submodule changed At least one submodule changed in this PR. label Nov 10, 2026
@CheSema
CheSema marked this pull request as ready for review November 10, 2026 14:57
@davenger davenger self-assigned this Nov 10, 2026
@davenger

Copy link
Copy Markdown
Member

LGTM

@watson-ch

watson-ch Bot commented Nov 10, 2026

Copy link
Copy Markdown

Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/1699

Labels added:

  • v25.12-must-backport
  • v26.2-must-backport
  • v26.4-must-backport

These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels.

@clickhouse-gh clickhouse-gh Bot added the comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). label Nov 10, 2026
@CheSema
CheSema enabled auto-merge November 10, 2026 15:43
@clickhouse-gh

clickhouse-gh Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2e68ea565 with master 2f186f985 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

20 translation units recompiled, 108 s compile time in total, 20 of them have a recent master baseline.

Job report

@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 10, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 10, 2026
Backport #130517 to 26.8: Fix crash in log file rotation when the process has no free file descriptors
clickhouse-gh Bot added a commit that referenced this pull request Nov 10, 2026
Backport #130517 to 26.9: Fix crash in log file rotation when the process has no free file descriptors
PedroTadim added a commit that referenced this pull request Nov 11, 2026
Backport #130517 to 26.3: Fix crash in log file rotation when the process has no free file descriptors
CheSema added a commit that referenced this pull request Nov 11, 2026
Backport #130517 to 26.10: Fix crash in log file rotation when the process has no free file descriptors
groeneai pushed a commit to groeneai/ClickHouse that referenced this pull request Nov 12, 2026
…hen the process has no free file descriptors
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR. v25.12-must-backport v26.2-must-backport v26.4-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants