Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] - Improve seekability check for stdout pipes in BufferedReadSeeker #3189

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

ahrav
Copy link
Collaborator

@ahrav ahrav commented Aug 6, 2024

Description:

When handling files over stdout.Pipe, our current method of checking if a reader is seekable using a simple interface assertion is insufficient. The underlying type of the response from stdout.Pipe is an os.File, which typically implements the io.Seeker interface. However, in this case, it cannot be treated like a regular file and doesn't support seeking operations.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@ahrav ahrav marked this pull request as ready for review August 6, 2024 23:45
@ahrav ahrav requested review from a team as code owners August 6, 2024 23:45
Copy link
Collaborator

@rosecodym rosecodym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has a few changes that don't appear related to the described fix - are they actually related?

pkg/handlers/handlers_test.go Outdated Show resolved Hide resolved
pkg/iobuf/bufferedreaderseeker.go Outdated Show resolved Hide resolved
pkg/iobuf/bufferedreaderseeker.go Outdated Show resolved Hide resolved
@ahrav ahrav requested review from rosecodym and a team August 7, 2024 17:33
@ahrav
Copy link
Collaborator Author

ahrav commented Aug 7, 2024

This has a few changes that don't appear related to the described fix - are they actually related?

Removed. Will add to a separate PR.

@ahrav
Copy link
Collaborator Author

ahrav commented Aug 7, 2024

This has a few changes that don't appear related to the described fix - are they actually related?

Removed. Will add to a separate PR.

Added here

Comment on lines +37 to +38
seeker io.Seeker // If the reader supports seeking, it's stored here for direct access
isSeekable bool // Indicates if the reader supports reliable seeking operations
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to remove isSeekable in favor of checking seeker != nil?

Comment on lines 82 to 84
if isSeekable(r) {
seeker, _ = r.(io.Seeker)
seekable = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's only used here, I'd suggest changing isSeekable to:

func asSeeker(r io.Reader) io.Seeker { /* ... */ }

and using it like:

if s := asSeeker(r); s != nil {
    seeker = s
} else {
    buf = defaultBufferPool.Get()
}

or maybe

seeker = asSeeker(r)
if seeker == nil {
    buf = defaultBufferPool.Get()
}

Comment on lines 85 to 87
seeker = asSeeker(r)
if seeker == nil {
isSeekable = true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isSeekable should be set to false, correct? But what do you think about removing isSeekable altogether in favor of seeker != nil checks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants