Skip to content

fix(socketcan): handle OSError when enabling SO_TIMESTAMPNS - #2176

Merged
zariiii9003 merged 1 commit into
hardbyte:mainfrom
M-Colley:fix/issue-1538-socketcan-timestampns
Dec 1, 2026
Merged

zariiii9003 merged 1 commit into
hardbyte:mainfrom
M-Colley:fix/issue-1538-socketcan-timestampns

Conversation

@M-Colley

@M-Colley M-Colley commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

SocketcanBus.__init__ sets SO_TIMESTAMPNS without catching OSError, causing bus initialization to fail with ENOPROTOOPT ([Errno 92] Protocol not available) in containerized or virtualized SocketCAN environments where the socket option is unsupported. All other setsockopt calls in SocketcanBus.__init__ already catch and log OSError.

This patch wraps the SO_TIMESTAMPNS setsockopt call in can/interfaces/socketcan/socketcan.py in try/except OSError and updates capture_message to fall back to time.time() when ancillary_data is empty. Unit tests in test/test_socketcan.py and a changelog fragment cover ENOPROTOOPT during initialization and empty ancillary_data on receive.

Fixes #1538

Catch and log OSError on setsockopt(SO_TIMESTAMPNS) in SocketcanBus.__init__ to match other socket options, and fall back to time.time() in capture_message when ancillary_data is empty.

Fixes hardbyte#1538

@zariiii9003 zariiii9003 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@zariiii9003
zariiii9003 merged commit 64f2b79 into hardbyte:main Dec 1, 2026
24 of 26 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.

OSError 92: Protocol not available inside SocketcanBus.__init__

2 participants