Skip to content

fix: skip FileDescriptorsLen fast path on non-Linux/FreeBSD platforms#853

Open
kazeburo wants to merge 1 commit into
prometheus:masterfrom
kazeburo:fix-isrealproc-function
Open

fix: skip FileDescriptorsLen fast path on non-Linux/FreeBSD platforms#853
kazeburo wants to merge 1 commit into
prometheus:masterfrom
kazeburo:fix-isrealproc-function

Conversation

@kazeburo

Copy link
Copy Markdown

Summary

Fix Proc.FileDescriptorsLen() returning incorrect values on macOS and other non-Linux/FreeBSD platforms where isRealProc() was incorrectly returning true.

Problem

On macOS, Proc.FileDescriptorsLen() returns incorrect values because the fast path (introduced in Linux v6.2) relies on stat.Size() semantics that are only valid on Linux. For example, on macOS with test fixtures, this caused:

proc_test.go:246: want fds 5, have 224

The fast path uses stat.Size() to get the directory entry count, which on macOS returns directory metadata (e.g., inode count or block size) instead of the actual number of file descriptors.

This happened because isRealProc() in fs_statfs_notype.go was returning true on non-Linux/FreeBSD platforms, causing the fast path to be incorrectly applied.

Changes

  • Update isRealProc() in fs_statfs_notype.go to return false, nil instead of true, nil

This ensures that on platforms without Statfs_t.Type (macOS, etc.), the fast path is skipped and the correct result from len(fds) is returned.

The fast path relying on stat.Size() semantics for directory block counts is only valid on Linux and FreeBSD, so returning false on other platforms is semantically correct.

Impact

  • Linux/FreeBSD: No change in behavior — fs_statfs_type.go continues to check PROC_SUPER_MAGIC
  • macOS and other platforms: FileDescriptorsLen() now returns the correct file descriptor count instead of directory metadata values

Signed-off-by: Masahiro Nagano <m-nagano@sakura.ad.jp>
@kazeburo
kazeburo force-pushed the fix-isrealproc-function branch from 83b9adb to 621343b Compare July 24, 2026 09:21
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.

1 participant