{"record":{"id":"1c7e51181dc7c602","repo":"bazelbuild/bazel","slug":"could-not-seek-to-end-of-file-s","errorCode":null,"errorMessage":"Could not seek to end of file (%s)\n","messagePattern":"Could not seek to end of file \\((.+?)\\)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main/cpp/blaze_util_windows.cc","lineNumber":583,"sourceCode":"  // If the previous server process was asked to be shut down (but not killed),\n  // it takes a while for it to comply, so wait until the JVM output file that\n  // it held open is closed. There seems to be no better way to wait for a file\n  // to be closed on Windows.\n  static const unsigned int timeout_sec = 60;\n  for (unsigned int waited = 0; waited < timeout_sec; ++waited) {\n    HANDLE handle = ::CreateFileW(\n        /* lpFileName */ path.AsNativePath().c_str(),\n        /* dwDesiredAccess */ GENERIC_READ | GENERIC_WRITE,\n        /* dwShareMode */ FILE_SHARE_READ,\n        /* lpSecurityAttributes */ sa,\n        /* dwCreationDisposition */\n        daemon_out_append ? OPEN_ALWAYS : CREATE_ALWAYS,\n        /* dwFlagsAndAttributes */ FILE_ATTRIBUTE_NORMAL,\n        /* hTemplateFile */ nullptr);\n    if (handle != INVALID_HANDLE_VALUE) {\n      if (daemon_out_append &&\n          !SetFilePointerEx(handle, {}, nullptr, FILE_END)) {\n        fprintf(stderr, \"Could not seek to end of file (%s)\\n\",\n                path.AsPrintablePath().c_str());\n        return INVALID_HANDLE_VALUE;\n      }\n      return handle;\n    }\n    if (GetLastError() != ERROR_SHARING_VIOLATION &&\n        GetLastError() != ERROR_LOCK_VIOLATION) {\n      // Some other error occurred than the file being open; bail out.\n      break;\n    }\n\n    // The file is still held open, the server is shutting down. There's a\n    // chance that another process holds it open, we don't know; in that case\n    // we just exit after the timeout expires.\n    if (waited == 5 || waited == 10 || waited == 30) {\n      fprintf(stderr,\n              \"Waiting for previous Bazel server's log file to close \"\n              \"(waited %d seconds, waiting at most %d)\\n\",","sourceCodeStart":565,"sourceCodeEnd":601,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/cpp/blaze_util_windows.cc#L565-L601","documentation":"While restarting a Bazel server on Windows, the client opens the previous server's jvm.out log with OPEN_ALWAYS for append; if SetFilePointerEx(handle, {}, nullptr, FILE_END) fails it prints this message and returns INVALID_HANDLE_VALUE, so the new server's log file cannot be set up. It means Windows refused to seek to end-of-file on a handle that was successfully opened for read/write.","triggerScenarios":"Starting Bazel with the same output_base while the old server is shutting down and jvm.out is still held with an incompatible sharing mode; the file being replaced/locked by backup or antivirus software between CreateFileW and the seek; handle opened on a device or redirected filesystem (network drive) that does not support seeking.","commonSituations":"Rapidly restarting Bazel on Windows (Ctrl-C then immediate rerun); jvm.out on a synced/network share; third-party file filters holding the log; a previous crash leaving the log handle in an odd state.","solutions":["Run 'bazel shutdown' and wait a few seconds before the next command.","If it persists, stop all bazel processes (taskkill /IM bazel.exe /F and the java server) and retry.","Move the output base off network/synced storage: bazel --output_base=C:/_bazel_user/... or exclude it from sync/AV scanning.","As a last resort delete output_base/server/jvm.out while no server runs so a fresh log is created with CREATE_ALWAYS.","Check the Windows Application event log for filesystem/driver errors on the volume holding the output base."],"exampleFix":"# before: rapid restart loop hits the message\nbazel shutdown\ntimeout /t 5\nbazel build //pkg\n# persistent case: fresh log file\ntaskkill /IM bazel.exe /F 2>nul\ndel %OUTPUT_BASE%\\server\\jvm.out\nbazel build //pkg","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call 'bazel shutdown' before restarting on the same output_base.","Keep output_base on a local NTFS volume, not network/synced storage.","Give concurrent jobs separate --output_base values.","Retry the Bazel command once after a few seconds; the seek usually succeeds once the old server exits."],"tags":["windows","server","log-file","restart","file-handle","win32"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}