Skip to content

Keep thread names longer than 15 characters on macOS - #1008

Merged
odygrd merged 1 commit into
odygrd:masterfrom
MaxFreedomPollard:fix/macos-thread-name-truncation
Oct 24, 2026
Merged

odygrd merged 1 commit into
odygrd:masterfrom
MaxFreedomPollard:fix/macos-thread-name-truncation

Conversation

@MaxFreedomPollard

Copy link
Copy Markdown
Contributor

detail::get_thread_name() reads the calling thread's name into a 16-byte buffer on every non-Windows platform (include/quill/backend/ThreadUtilities.h). 16 bytes is the Linux limit, but macOS keeps thread names of up to 63 bytes, and pthread_getname_np() only copies what fits in the buffer it is given. The name is read once per thread and cached, so %(thread_name), and the thread_name passed to sinks and filters, only ever shows the first 15 characters of a longer name. The Windows branch already reads up to 256 characters.

A thread named network-receiver-thread-01 logging with the pattern [%(thread_name)] %(message):

master:  [network-receive] hello from a named thread
this PR: [network-receiver-thread-01] hello from a named thread

The fix sizes the buffer for 64 bytes (MAXTHREADNAMESIZE on macOS) and passes sizeof(thread_name) instead of the hard-coded 16. Linux caps thread names at 15 characters, so the result there is unchanged. The FreeBSD/OpenBSD branch reads into the same buffer; I could only verify on macOS.

The new get_thread_name_returns_names_longer_than_15_characters unit test names the current thread with set_thread_name() and checks that get_thread_name() returns the full name. It runs on macOS and returns early elsewhere, like the Linux-only set_thread_name_validates_length test next to it. I added an Unreleased changelog entry.

Verified on macOS arm64 with Apple clang 21:

  • cmake -S . -B build -G Ninja -DQUILL_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug, then cmake --build build --target TEST_BackendUtilities.
  • On master the new test fails with REQUIRE_EQ( quill-thread-na, quill-thread-name-longer-than-15 ). With the change it passes.
  • Full ctest run after rebuilding all test targets: 437 of 446 pass. The 9 failures are the backend lock-file tests and the stdout/stderr capture tests, which need to create files directly in /tmp. My build environment blocks that, and the same 9 fail on master.

🤖 Generated with Claude Code

get_thread_name() read the calling thread's name into a 16-byte buffer on
every non-Windows platform. 16 bytes is the Linux limit, but macOS keeps
thread names of up to 63 bytes and pthread_getname_np() only copies what
fits in the supplied buffer, so %(thread_name) showed only the first 15
characters of longer names. Size the buffer for 64 bytes instead. Linux
still returns at most 15 characters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@odygrd
odygrd merged commit 4a026e1 into odygrd:master Oct 24, 2026
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants