microsoft/FASTER · error · IOException

Error writing to log file

Error message

Error writing to log file

What it means

WriteAsync issues an overlapped Win32 write on the segment file. If the native call fails immediately (returns false with a last error other than ERROR_IO_PENDING), an IOException wrapping the Win32 error code is thrown.

Solutions

  1. Check the wrapped Win32 error code to identify the cause (disk full, handle invalid, etc.) and free disk space or fix handle lifetime accordingly.
  2. Ensure the device is not disposed while writes are in flight — coordinate shutdown with the epoch system / flush.
  3. Reduce concurrent pending I/O (lower ThrottleLimit pressure) if hitting resource limits.
  4. Verify write addresses and lengths are within the segment and aligned to sector size.
Defensive patterns

Strategy: try-catch

Validate before calling

long free = new DriveInfo(Path.GetPathRoot(logDirectory)).AvailableFreeSpace;
if (free < requiredBytes) throw new IOException("Insufficient disk space for log write");

Try / catch

try { device.WriteAsync(...); } catch (IOException e) { log.LogError(e, "Segment write failed (hr=0x{Hr:X})", e.HResult); throw; }

Prevention

When it happens

Trigger: Calling WriteAsync with an invalid/closed segment handle, a full disk, an offset beyond disk capacity, or after the device was disposed; also ERROR_NO_SYSTEM_RESOURCES under heavy pending-I/O load.

Common situations: Disk-full during hybrid log flush; writing after device dispose during shutdown races; antivirus/backup tools locking segment files; too many outstanding overlapped I/Os.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of microsoft/FASTER@321d872eab (2026-09-15). Data as JSON: /api/errors/258b0a8d765184bb. Report an issue: GitHub.

Appendix: source

Thrown at cs/src/core/Device/LocalStorageDevice.cs:310

            try
            {
                Interlocked.Increment(ref numPending);

                var logHandle = GetOrAddHandle(segmentId);

                bool _result = Native32.WriteFile(logHandle,
                                        sourceAddress,
                                        numBytesToWrite,
                                        out uint bytesWritten,
                                        ovNative);

                if (!_result)
                {
                    int error = Marshal.GetLastWin32Error();
                    if (error != Native32.ERROR_IO_PENDING)
                    {
                        throw new IOException("Error writing to log file", error);
                    }
                }
            }
            catch (IOException e)
            {
                Interlocked.Decrement(ref numPending);
                callback((uint)(e.HResult & 0x0000FFFF), 0, context);
                results.Enqueue(result);
            }
            catch
            {
                Interlocked.Decrement(ref numPending);
                callback(uint.MaxValue, 0, context);
                results.Enqueue(result);
            }
        }

        /// <summary>

View on GitHub (pinned to 321d872eab)