Skip to content

GH-49433: [C++] Buffer ARROW_LOG output to prevent thread interleaving#49663

Open
Shockp wants to merge 1 commit intoapache:mainfrom
Shockp:fix-thread-safe-logging
Open

GH-49433: [C++] Buffer ARROW_LOG output to prevent thread interleaving#49663
Shockp wants to merge 1 commit intoapache:mainfrom
Shockp:fix-thread-safe-logging

Conversation

@Shockp
Copy link
Copy Markdown

@Shockp Shockp commented Apr 5, 2026

Rationale for this change

When using the C++ ARROW_LOG macros from multiple threads, messages often get mingled together in stderr because the operator<< writes directly to the global stream piece-by-piece, which is not thread-safe.

What changes are included in this PR?

This PR introduces an internal std::ostringstream buffer to the fallback CerrLog class.
Instead of writing to std::cerr immediately on every << operation, the messages are accumulated locally within the CerrLog instance. The completed string is then flushed atomically to std::cerr upon the object's destruction.

Are these changes tested?

Yes. I built the C++ project locally and ran the test suite (ctest) to ensure no existing logging behavior or IPC functionality was broken.

Are there any user-facing changes?

No API changes. Users will simply notice that multi-threaded ARROW_LOG console output is now cleanly separated per line instead of interleaved.

Closes #49433

…leaving

When using the ARROW_LOG macros from multiple threads, messages were getting
mingled together in stderr because the operator<< was writing directly to
the global stream piece-by-piece.

This commit introduces an internal std::ostringstream buffer to CerrLog so
that messages are accumulated locally and flushed atomically upon destruction.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

⚠️ GitHub issue #49433 has been automatically assigned in GitHub to PR creator.

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.

[C++] Multi-threaded logging can mix up messages

1 participant