kubernetes/kops · error

writing to sftp temp file: %w

Error message

writing to sftp temp file: %w

What it means

WriteFile streams the caller's io.ReadSeeker into the SFTP temp file with io.Copy. If the copy fails mid-transfer (network interruption, SFTP server-side write failure, disk full), the error is wrapped with this message. The deferred cleanup then removes the orphaned temp file.

Source

Thrown at util/pkg/vfs/sshfs.go:212

		if shouldClose {
			// Something went wrong; try to close the temp file
			if err := f.Close(); err != nil {
				klog.Warningf("unable to close temp file %q: %v", tempfile, err)
			}
		}
	}()

	deleteTempFile := true
	defer func() {
		if deleteTempFile {
			// Something went wrong; try to remove the temp file
			if err := sftpClient.Remove(tempfile); err != nil {
				klog.Warningf("unable to remove temp file %q: %v", tempfile, err)
			}
		}
	}()
	if _, err := io.Copy(f, data); err != nil {
		return fmt.Errorf("writing to sftp temp file: %w", err)
	}

	shouldClose = false
	if err := f.Close(); err != nil {
		return err
	}

	if acl != nil {
		sshACL, ok := acl.(*SSHAcl)
		if !ok {
			return fmt.Errorf("unexpected acl type %T", acl)
		} else {
			err = sftpClient.Chmod(tempfile, sshACL.Mode)
			if err != nil {
				return fmt.Errorf("error during chmod of %q: %w", tempfile, err)
			}
		}
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Retry the operation — the temp file is cleaned up automatically so a retry is safe.
  2. Check network stability to the SSH host (ping, ssh keepalives: ServerAliveInterval in ~/.ssh/config).
  3. Check remote disk space (`df -h`) if the wrapped error indicates write failure/ENOSPC.
  4. For large files, investigate SFTP subsystem limits or MTU/VPN issues on the path.

Example fix

// before: flaky VPN drops connection during large write
kops update cluster ... // fails: writing to sftp temp file: EOF
// after: enable ssh keepalives in ~/.ssh/config
Host mynode
  ServerAliveInterval 30
  ServerAliveCountMax 6
Defensive patterns

Strategy: retry

Validate before calling

// probe connection stability before large writes
conn, err := net.DialTimeout("tcp", host+":22", 5*time.Second)
if err != nil { return fmt.Errorf("host unreachable: %w", err) }
conn.Close()

Try / catch

err := path.WriteFile(ctx, data, acl)
if err != nil && strings.Contains(err.Error(), "writing to sftp temp file") {
    if netErr, ok := errors.Unwrap(err).(net.Error); ok && netErr.Timeout() {
        time.Sleep(backoff)
        return path.WriteFile(ctx, data, acl) // temp file was cleaned up; safe
    }
    return err
}

Prevention

When it happens

Trigger: io.Copy(f, data) fails during WriteFile: SSH connection dropped mid-write, remote disk filled during transfer, SFTP server returned an I/O error, or the source reader itself errored.

Common situations: Flaky network or SSH keepalive timeouts when pushing large cluster state files to a node; disk-full on remote node during large writes; firewall/NAT dropping long-lived SSH connections.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/2259c1dfa4cb3287. Report an issue: GitHub.