kubernetes/kops · error

error reading data: %v

Error message

error reading data: %v

What it means

MemFSPath.WriteFile reads the full contents from the provided io.ReadSeeker before storing them in the in-memory filesystem. This error wraps any failure from that read (e.g. an already-closed reader or an underlying read error).

Source

Thrown at util/pkg/vfs/memfs.go:111

		child := current.children[token]
		if child == nil {
			child = &MemFSPath{
				context:  p.context,
				location: path.Join(current.location, token),
			}
			current.children[token] = child
		}
		current = child
		current.mutex.Lock()
		defer current.mutex.Unlock()
	}
	return current
}

func (p *MemFSPath) WriteFile(ctx context.Context, r io.ReadSeeker, acl ACL) error {
	data, err := io.ReadAll(r)
	if err != nil {
		return fmt.Errorf("error reading data: %v", err)
	}
	p.contents = data
	p.acl = acl
	return nil
}

func (p *MemFSPath) CreateFile(ctx context.Context, data io.ReadSeeker, acl ACL) error {
	// Check if exists
	if p.contents != nil {
		return os.ErrExist
	}

	return p.WriteFile(ctx, data, acl)
}

// ReadFile implements Path::ReadFile
func (p *MemFSPath) ReadFile(ctx context.Context) ([]byte, error) {
	if p.contents == nil {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Ensure the io.ReadSeeker is freshly positioned/valid; recreate the reader (e.g. bytes.NewReader(data)) before each WriteFile
  2. Check the wrapped %v error for the underlying read cause (e.g. 'file already closed') and fix the reader's lifecycle
  3. If retrying, Seek the reader back to offset 0 first since WriteFile consumes the whole stream

Example fix

// before
f, _ := os.Open(path); defer f.Close()
upload(ctx, f) // second call fails: reader consumed/closed
// after
upload := func() error {
    f, err := os.Open(path)
    if err != nil { return err }
    defer f.Close()
    return upload(ctx, f)
}
Defensive patterns

Strategy: validation

Validate before calling

if rs, ok := r.(io.Seeker); ok { if _, err := rs.Seek(0, io.SeekStart); err != nil { return err } }

Type guard

null

Try / catch

if err := p.WriteFile(ctx, r, acl); err != nil {
    if strings.HasPrefix(err.Error(), "error reading data:") {
        // recreate reader and retry once
    }
    return err
}

Prevention

When it happens

Trigger: Calling WriteFile (directly or via vfs CreateFile/WriteTo) with an io.ReadSeeker whose Read fails — most commonly a reader already consumed and closed, or a failing bytes/string wrapper.

Common situations: Reusing a bytes.Reader/file after a prior upload exhausted it; passing a network-backed reader that errors mid-read when writing test clusters to memfs://.

Related errors


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