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
- Retry the operation — the temp file is cleaned up automatically so a retry is safe.
- Check network stability to the SSH host (ping, ssh keepalives: ServerAliveInterval in ~/.ssh/config).
- Check remote disk space (`df -h`) if the wrapped error indicates write failure/ENOSPC.
- 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
- Configure SSH keepalives (ServerAliveInterval) for long transfers.
- Keep transfers small or chunk large state files.
- Alert on remote disk-full conditions (ENOSPC) before they break writes.
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
- error creating sftp client: %w
- error creating sftp client (in new-session): %w
- error creating sftp client (at stdin pipe): %w
- reading primary MAC address from ec2 metadata: %w
- reading body %q: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/2259c1dfa4cb3287.
Report an issue: GitHub.