wavetermdev/waveterm · warning
context cancelled: %v
Error message
context cancelled: %v
What it means
ReadFileStream streams file contents from a remote host over the fileshare protocol. It selects on the caller's context; when ctx is done (cancelled or deadline exceeded) it aborts the stream and returns this error carrying context.Cause.
Source
Thrown at pkg/remote/fileshare/fsutil/fsutil.go:77
}
return fspath.Join(newParts...), nil
}
func ReadFileStream(ctx context.Context, readCh <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData], fileInfoCallback func(finfo wshrpc.FileInfo), dirCallback func(entries []*wshrpc.FileInfo) error, fileCallback func(data io.Reader) error) error {
var fileData *wshrpc.FileData
firstPk := true
isDir := false
drain := true
defer func() {
if drain {
utilfn.DrainChannelSafe(readCh, "ReadFileStream")
}
}()
for {
select {
case <-ctx.Done():
return fmt.Errorf("context cancelled: %v", context.Cause(ctx))
case respUnion, ok := <-readCh:
if !ok {
drain = false
return nil
}
if respUnion.Error != nil {
return respUnion.Error
}
resp := respUnion.Response
if firstPk {
firstPk = false
// first packet has the fileinfo
if resp.Info == nil {
return fmt.Errorf("stream file protocol error, first pk fileinfo is empty")
}
fileData = &resp
if fileData.Info.IsDir {
isDir = trueView on GitHub (pinned to a4447c1563)
Solutions
- Increase the context timeout for large transfers
- Retry with a fresh context — the stream is aborted, not resumable
- Check remote host responsiveness/network stability
- Propagate parent cancellation intentionally if this is expected shutdown
Example fix
// before ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) // too short data, err := fsutil.ReadStreamToFileData(ctx, ctl, "/big/file") // after ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) data, err := fsutil.ReadStreamToFileData(ctx, ctl, "/big/file")
Defensive patterns
Strategy: retry
Validate before calling
if ctx.Err() != nil {
return fmt.Errorf("context already done before stream: %w", ctx.Err())
} Try / catch
data, err := fsutil.ReadStreamToFileData(ctx, ctl, path)
if err != nil && errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) || strings.Contains(err.Error(), "context cancelled") {
ctx2, cancel := context.WithTimeout(context.Background(), longerTimeout)
defer cancel()
data, err = fsutil.ReadStreamToFileData(ctx2, ctl, path)
} Prevention
- Size timeouts to the transfer volume (large dirs need more)
- Only cancel contexts intentionally; propagate cancel to UI
- Monitor remote latency to set realistic deadlines
When it happens
Trigger: ReadStreamToFileData (or a direct ReadFileStream call) with a context that is cancelled or whose deadline expires while waiting on readCh from the remote stream.
Common situations: Slow or hung remote host exceeding the caller's timeout; user cancels a large directory-listing/download; upstream request cancelled (client disconnect); network stall causing deadline to fire.
Related errors
- getting file info: %w
- timeout waiting for port
- cancelled while waiting for app port: %w
- route did not establish after successful reconnection: %w
- error getting connection name from context: %v
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/7afe72e0e7d1198c.
Report an issue: GitHub.