{"record":{"id":"5a1cdf30239ded6a","repo":"microsoft/FASTER","slug":"asyncflushpagestofile-error-u","errorCode":null,"errorMessage":"AsyncFlushPagesToFile(), error: %u\n","messagePattern":"AsyncFlushPagesToFile\\(\\), error: %u\n","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cc/src/core/persistent_memory_malloc.h","lineNumber":939,"sourceCode":"    Context(std::atomic<uint32_t>& flush_pending_)\n      : flush_pending{ flush_pending_ } {\n    }\n    /// The deep-copy constructor\n    Context(Context& other)\n      : flush_pending{ other.flush_pending } {\n    }\n   protected:\n    Status DeepCopy_Internal(IAsyncContext*& context_copy) final {\n      return IAsyncContext::DeepCopy_Internal(*this, context_copy);\n    }\n   public:\n    std::atomic<uint32_t>& flush_pending;\n  };\n\n  auto callback = [](IAsyncContext* ctxt, Status result, size_t bytes_transferred) {\n    CallbackContext<Context> context{ ctxt };\n    if(result != Status::Ok) {\n      log_error(\"AsyncFlushPagesToFile(), error: %u\\n\", static_cast<uint8_t>(result));\n    }\n    assert(context->flush_pending > 0);\n    --context->flush_pending;\n  };\n\n  uint32_t num_pages = until_address.page() - start_page;\n  if(until_address.offset() > 0) {\n    ++num_pages;\n  }\n  assert(num_pages > 0);\n  flush_pending = num_pages;\n\n  for(uint32_t flush_page = start_page; flush_page < start_page + num_pages; ++flush_page) {\n    Address page_start_address{ flush_page, 0 };\n    Address page_end_address{ flush_page + 1, 0 };\n    Context context{ flush_pending };\n    RETURN_NOT_OK(file.WriteAsync(Page(flush_page), kPageSize * (flush_page - start_page),\n                                  kPageSize, callback, context));","sourceCodeStart":921,"sourceCodeEnd":957,"githubUrl":"https://github.com/microsoft/FASTER/blob/321d872eabda6a0345c8bd76419f89723ed864ae/cc/src/core/persistent_memory_malloc.h#L921-L957","documentation":"This log_error fires inside the completion callback of PersistentMemoryMalloc::AsyncFlushPagesToFile, which asynchronously writes log pages out to a file. If the async write completes with a Status other than Status::Ok, the callback logs the status code; the pending-flush counter is then still decremented, so callers waiting on flush_pending will proceed even though the on-disk copy is incomplete or corrupt.","triggerScenarios":"Calling AsyncFlushPagesToFile (used when persisting the log to a backing file, e.g. during dump-to-disk when memory is full or on truncation) and the underlying async file write fails: disk full, invalid/unwritable file path, device I/O error, or the device being disposed while writes are pending.","commonSituations":"Dumping the in-memory log to a file on a nearly full or failing disk; a file opened at an invalid path or without write permission; process shutdown racing with in-flight async writes.","solutions":["Map the logged status code to the actual file I/O failure and check the target file path, permissions, and free space","Reopen or recreate the backing file at a valid, writable location and retry the flush","Avoid disposing the device while flushes are pending; wait for flush_pending to reach zero before shutdown","After a failed flush, do not trust the file copy — re-run the flush and validate the resulting file before deleting in-memory data"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before dumping the log to file, ensure the target is writable\nstd::FILE* f = std::fopen(dump_path.c_str(), \"ab\");\nbool writable = (f != nullptr);\nif (f) std::fclose(f);","typeGuard":null,"tryCatchPattern":"// flush_pending reaching zero does not mean success; poll/inspect logged failures\nif (flush_failed.load()) { // set from your own tracking of 'AsyncFlushPagesToFile(), error' logs\n  std::cerr << \"Log dump incomplete; do not discard in-memory log\\n\";\n  // recreate the dump file and retry the flush\n}","preventionTips":["Verify the dump file path is valid and writable before triggering AsyncFlushPagesToFile","Ensure sufficient disk space for the full log dump; dumps of large logs fail otherwise","Wait for flush_pending to hit zero before closing/disposing the device","Validate the dumped file (size/page count) before deleting or truncating in-memory state"],"tags":["async-io","file-write","disk-flush","faster"],"backgroundTag":"file-write-failed","analyzedSha":"321d872eabda6a0345c8bd76419f89723ed864ae","analyzedAt":"2026-09-15T22:18:00.693Z","contentChangedAt":"2026-09-15T22:18:00.693Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}