abiosoft/colima · error

cannot seek to start of file: %w

Error message

cannot seek to start of file: %w

What it means

Immediately after a successful truncate (case: 200 response with existing partial), file.Seek(0, 0) on the same descriptor failed. It is the same failure class as error 266 — the underlying file or storage went bad mid-operation; the fd was valid because truncate had just succeeded on it.

Source

Thrown at util/downloader/http.go:163

	if err != nil {
		return nil, &NetworkError{Op: "download", URL: opts.URL, Err: err}
	}
	defer func() { _ = resp.Body.Close() }()

	// store final URL after redirects
	result.FinalURL = resp.Request.URL.String()
	result.ETag = resp.Header.Get("ETag")

	// handle response status
	switch resp.StatusCode {
	case http.StatusOK: // 200 - Full content (resume not supported or If-Range failed)
		if existingSize > 0 {
			// server sent full content, need to truncate and start over
			if err := file.Truncate(0); err != nil {
				return nil, fmt.Errorf("cannot truncate file for fresh download: %w", err)
			}
			if _, err := file.Seek(0, 0); err != nil {
				return nil, fmt.Errorf("cannot seek to start of file: %w", err)
			}
			existingSize = 0
		}
		result.TotalBytes = resp.ContentLength

	case http.StatusPartialContent: // 206 - Resume successful
		result.WasResumed = true
		// Content-Range: bytes 21010-47021/47022
		contentRange := resp.Header.Get("Content-Range")
		if totalSize := parseContentRangeTotal(contentRange); totalSize > 0 {
			result.TotalBytes = totalSize
		} else {
			result.TotalBytes = existingSize + resp.ContentLength
		}

	case http.StatusRequestedRangeNotSatisfiable: // 416
		// file is likely complete or server doesn't support range
		return nil, &HTTPStatusError{

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Remove the .downloading partial and .resume info and retry fresh
  2. Check disk health (Disk Utility, smartctl) and remount the volume
  3. Exclude the cache dir from real-time AV scanning
Defensive patterns

Strategy: retry

Try / catch

err := fileDownloader.Download(req, dest)
if err != nil && strings.Contains(err.Error(), "cannot seek to start of file") {
    base := strings.TrimSuffix(dest, ".downloading")
    _ = os.Remove(dest)
    _ = os.Remove(base + ".resume")
    err = fileDownloader.Download(req, dest)
}
if err != nil {
    return err
}

Prevention

When it happens

Trigger: Storage I/O error or external interference (unmounted volume, AV file-locking) on the .downloading file during the restart-from-zero after a 200 response.

Common situations: Failing or ejected disk holding the cache; aggressive antivirus scanning the cache dir.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/63c313f2bb2ed481. Report an issue: GitHub.