Repository navigation
fix(fast_io): IOCP writer_from_file overlapped flag + typed error handling (#1929, #1930) - #3608
Merged
Merged
Conversation
…dling (#1929, #1930) #1929: IOCP writer_from_file now correctly handles std::fs::File handles that lack FILE_FLAG_OVERLAPPED. Under IocpPolicy::Enabled the path is recovered via GetFinalPathNameByHandleW, the original handle is dropped, and the file is reopened through IocpWriter::create_for_append with FILE_FLAG_OVERLAPPED. Anonymous handles (pipes, unnamed temp files) are rejected with a clear ErrorKind::Unsupported message that names the underlying FILE_FLAG_OVERLAPPED requirement. IocpPolicy::Auto silently falls back to standard buffered I/O on any failure. #1930: Two Win32 error codes are now mapped to typed IocpError variants: - ERROR_INVALID_PARAMETER (87) -> IocpError::InvalidOperation, returned by WriteFile/ReadFile/GetQueuedCompletionStatus(Ex) call sites in the file reader, file writer, and completion pump. Maps to io::ErrorKind::InvalidInput. - ERROR_INSUFFICIENT_BUFFER (122) -> IocpError::InsufficientBuffer. The pump drain loop transparently doubles its OVERLAPPED_ENTRY buffer (capped at 8192 entries / 256 KiB) and retries, only surfacing the typed error if the cap is reached. Maps to io::ErrorKind::OutOfMemory. Both variants implement From<IocpError> for io::Error, so existing io::Result-returning APIs remain backwards compatible. Cross-platform stub mirrors the type for compile parity. Tests added (Windows-gated): - writer_from_file_enabled_reopens_with_overlapped: real file handle reopened as Iocp variant, content writes succeed. - writer_from_file_enabled_rejects_anonymous_handle: CreatePipe handle yields ErrorKind::Unsupported with FILE_FLAG_OVERLAPPED in the message. - writer_from_file_auto_falls_back_for_anonymous_handle: Auto policy never errors on a regular file (Iocp or Std both acceptable). - pump_drains_burst_larger_than_batch_size: 4x batch-size completion burst dispatches without loss, exercising the dynamic-growth path. - iocp_error_insufficient_buffer_round_trips: typed variant maps to OutOfMemory and preserves request/capacity in the message. - error.rs: 6 unit tests covering both variants, code recognition helpers, and classify_overlapped_error pass-through.
oferchen
added a commit
that referenced
this pull request
May 5, 2026
…dling (#1929, #1930) (#3608) * fix(fast_io): IOCP writer_from_file overlapped flag + typed error handling (#1929, #1930) #1929: IOCP writer_from_file now correctly handles std::fs::File handles that lack FILE_FLAG_OVERLAPPED. Under IocpPolicy::Enabled the path is recovered via GetFinalPathNameByHandleW, the original handle is dropped, and the file is reopened through IocpWriter::create_for_append with FILE_FLAG_OVERLAPPED. Anonymous handles (pipes, unnamed temp files) are rejected with a clear ErrorKind::Unsupported message that names the underlying FILE_FLAG_OVERLAPPED requirement. IocpPolicy::Auto silently falls back to standard buffered I/O on any failure. #1930: Two Win32 error codes are now mapped to typed IocpError variants: - ERROR_INVALID_PARAMETER (87) -> IocpError::InvalidOperation, returned by WriteFile/ReadFile/GetQueuedCompletionStatus(Ex) call sites in the file reader, file writer, and completion pump. Maps to io::ErrorKind::InvalidInput. - ERROR_INSUFFICIENT_BUFFER (122) -> IocpError::InsufficientBuffer. The pump drain loop transparently doubles its OVERLAPPED_ENTRY buffer (capped at 8192 entries / 256 KiB) and retries, only surfacing the typed error if the cap is reached. Maps to io::ErrorKind::OutOfMemory. Both variants implement From<IocpError> for io::Error, so existing io::Result-returning APIs remain backwards compatible. Cross-platform stub mirrors the type for compile parity. Tests added (Windows-gated): - writer_from_file_enabled_reopens_with_overlapped: real file handle reopened as Iocp variant, content writes succeed. - writer_from_file_enabled_rejects_anonymous_handle: CreatePipe handle yields ErrorKind::Unsupported with FILE_FLAG_OVERLAPPED in the message. - writer_from_file_auto_falls_back_for_anonymous_handle: Auto policy never errors on a regular file (Iocp or Std both acceptable). - pump_drains_burst_larger_than_batch_size: 4x batch-size completion burst dispatches without loss, exercising the dynamic-growth path. - iocp_error_insufficient_buffer_round_trips: typed variant maps to OutOfMemory and preserves request/capacity in the message. - error.rs: 6 unit tests covering both variants, code recognition helpers, and classify_overlapped_error pass-through. * style: cargo fmt --all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes two P0 beta-blocking IOCP bugs in
fast_io:Cache x86 checksum SIMD feature detection #1929 -
iocp::writer_from_filenow reopens std::fs::File handles withFILE_FLAG_OVERLAPPEDinstead of silently corrupting overlapped I/O. Path is recovered viaGetFinalPathNameByHandleW, the original handle is dropped, and the file is reopened through a newIocpWriter::create_for_appendthat usesOPEN_EXISTING+FILE_FLAG_OVERLAPPED. Anonymous handles (pipes, unnamed temp files) are rejected underIocpPolicy::Enabledwith a clearErrorKind::Unsupportedmessage namingFILE_FLAG_OVERLAPPEDand the typical culprits (named pipes, console handles, character devices).IocpPolicy::Autotransparently falls back to standard buffered I/O when path recovery or reopen fails.Optimize vectored rolling checksum aggregation #1930 - Two Win32 error codes are now mapped to typed
IocpErrorvariants:ERROR_INVALID_PARAMETER(87) ->IocpError::InvalidOperation { context }. Surfaced fromWriteFile,ReadFile,GetQueuedCompletionStatus, andGetQueuedCompletionStatusExcall sites infile_writer,file_reader, andpump. Maps toio::ErrorKind::InvalidInput.ERROR_INSUFFICIENT_BUFFER(122) ->IocpError::InsufficientBuffer { requested, capacity }. The pump drain loop transparently doubles itsOVERLAPPED_ENTRYbuffer (capped at 8192 entries / 256 KiB) and retries; the typed error is only surfaced if the cap is reached. Maps toio::ErrorKind::OutOfMemory.Both variants implement
From<IocpError> for io::Error, so existingio::Result-returning APIs stay backwards-compatible.Files modified
crates/fast_io/src/iocp/error.rs(new) -IocpErrorenum,is_invalid_parameter,is_insufficient_buffer,classify_overlapped_error.crates/fast_io/src/iocp/mod.rs- exporterrormodule and re-exportIocpError.crates/fast_io/src/iocp/file_factory.rs- rewritewriter_from_fileper Cache x86 checksum SIMD feature detection #1929; add privatepath_from_filehelper; add 3 Windows tests.crates/fast_io/src/iocp/file_writer.rs- factoropen_with_disposition; addIocpWriter::create_for_append; classify errors viaclassify_overlapped_error.crates/fast_io/src/iocp/file_reader.rs- classifyReadFileandGetQueuedCompletionStatuserrors.crates/fast_io/src/iocp/pump.rs- dynamic batch growth onERROR_INSUFFICIENT_BUFFER; classify default error path; add 2 tests.crates/fast_io/src/iocp_stub.rs- mirrorIocpErrorenum on non-Windows for type compatibility.crates/fast_io/src/lib.rs- re-exportIocpError.crates/fast_io/Cargo.toml- addWin32_System_Pipesfeature for theCreatePipe-based test.Coordination with #1897
Did not block this work. The completion pump from #1897 is already on master; this PR only modifies the drain loop's error-handling path (adds
ERROR_INSUFFICIENT_BUFFERretry andclassify_overlapped_errorupgrade) and leaves the pump's public API untouched.New error variants (signatures)
Test plan
error.rsunit tests on every platform (typed-error variants, kind mapping, code recognition, classify pass-through).writer_from_file_enabled_reopens_with_overlappedconfirms reopen produces anIocpvariant and writes succeed.writer_from_file_enabled_rejects_anonymous_handleconfirms anonymous (CreatePipe) handles are rejected withErrorKind::Unsupportedand the message namesFILE_FLAG_OVERLAPPED.writer_from_file_auto_falls_back_for_anonymous_handleconfirmsAutonever errors on a real file.pump_drains_burst_larger_than_batch_sizeconfirms a 4x batch burst dispatches every completion (exercises the dynamic growth path).iocp_error_insufficient_buffer_round_tripsconfirms the typed error maps toOutOfMemoryand preserves request/capacity in the message.iocp_stubtest suite (cross-platform compile parity preserved).