Skip to content

PartsReadCloser lost the reader #49

@zengxiaobai

Description

@zengxiaobai

getContents function:

     if index < len(availableChunks) {
		chunkFile, _ := getSliceChunkFile(c, availableChunks[index])
		if chunkFile != nil {
			if err := checkChunkSize(c, chunkFile, idx); err != nil {
				_ = chunkFile.Close()
				_ = c.bucket.Discard(context.Background(), c.id)
				return nil, 0, err
			}

			// Identify an anchor block and synchronize any missing blocks prior to the current index.
			toByte := min(c.md.Size-1, uint64(availableChunks[index]*uint32(partSize))-1)

			// Request is automatically cloned by getUpstreamReader
			reader, err := c.getUpstreamReader(fromByte, toByte, true)
			if err != nil {
				_ = chunkFile.Close()
				return nil, 0, err
			}

			return iobuf.PartsReadCloser(reader, chunkFile), int(availableChunks[index]-reqChunks[from]) + 1, nil
		}
	}

at
return iobuf.PartsReadCloser(reader, chunkFile), int(availableChunks[index]-reqChunks[from]) + 1, nil

the reader is passed to closer, so when first file chunk is removed, the resp body cannot read from uptream reader, then chunk file 。But only read from chunkfile .
iobuf.PartsReadCloser(reader, chunkFile), int(availableChunks[index]-reqChunks[from]) + 1, nil

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions