EINTR on write() – Unresolved Retry Policy
0 reputation · 12 Aug 2024, 23:22 UTC
EINTR on write() – Unresolved Retry Policy
The goal is to guarantee that a stream write completes without duplicating data when a POSIX write() call is interrupted.
POSIX allows the kernel to restart interrupted calls, but many programs choose to retry manually. The ambiguity around EINTR and partial writes creates a risk of resending bytes that the kernel already accepted. Developers must decide whether to rely on SA_RESTART, handle EINTR explicitly, or use an application‑level counter to track progress.
Unresolved questions remain:
- Should an application automatically retry after EINTR when SA_RESTART is absent?
- How can it detect if a retry would duplicate data following a partial write?
- Is there a portable method to avoid duplication when retrying writes that returned fewer bytes?