Skip to content

Improve socket error detection in unicast transport read#1162

Draft
sashacmc wants to merge 2 commits intomainfrom
unicast-read-error-handling
Draft

Improve socket error detection in unicast transport read#1162
sashacmc wants to merge 2 commits intomainfrom
unicast-read-error-handling

Conversation

@sashacmc
Copy link
Member

@sashacmc sashacmc commented Feb 19, 2026

Description

What does this PR do?

Improves error detection and handling in the unicast transport read path:

  • Enhanced socket error detection to distinguish between pending data, socket closure, and critical errors
  • Proper handling of socket closure events to allow reconnection
  • Changed _z_unicast_client_read return type from bool to int with distinct status codes
  • Exit read task when connection errors are detected instead of continuing to loop

Why is this change needed?

Previously, the unicast read function returned a simple boolean, which didn't distinguish between "no data available" and "socket closed/error". This could lead to:

  • Read task continuing to loop indefinitely on closed sockets
  • Inability to properly trigger reconnection logic
  • Unclear error states that made debugging difficult

This change enables proper reconnection handling by detecting when the socket is actually closed or experiencing critical errors.

Related Issues

Fixes #1010


🏷️ Label-Based Checklist

Based on the labels applied to this PR, please complete these additional requirements:

Labels: enhancement

✨ Enhancement Requirements

Since this PR enhances existing functionality:

  • Enhancement scope documented - Clear description of what is being improved
  • Minimum necessary code - Implementation is as simple as possible, doesn't overcomplicate the system
  • Backwards compatible - Existing code/APIs still work unchanged
  • No new APIs added - Only improving existing functionality
  • Tests updated - Existing tests pass, new test cases added if needed
  • Performance improvement measured - If applicable, before/after metrics provided
  • Documentation updated - Existing docs updated to reflect improvements
  • User impact documented - How users benefit from this enhancement

Remember: Enhancements should not introduce new APIs or breaking changes.

Instructions:

  1. Check off items as you complete them (change - [ ] to - [x])
  2. The PR checklist CI will verify these are completed

This checklist updates automatically when labels change, but preserves your checked boxes.

@sashacmc sashacmc added bug Something isn't working enhancement Things could work better and removed bug Something isn't working labels Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Things could work better

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Solving excessive read task CPU usage and question on TCP connection state handling

1 participant