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

NewReadOnly fails on exhausted ReadSeeker #336

Open
ribasushi opened this issue Oct 5, 2022 · 4 comments
Open

NewReadOnly fails on exhausted ReadSeeker #336

ribasushi opened this issue Oct 5, 2022 · 4 comments
Labels
P2 Medium: Good to have, but can wait until someone steps up

Comments

@ribasushi
Copy link

  • An os.File has GenerateIndex() called on
  • This puts the os.File's underlying Reader at EOF
  • If one then calls NewReadOnly the check here falls through to the io.Reader, sees the EOF and aborts

Observe the workaround at lines 81~83 in the sequence here. A potential fix is to rewind when the argument is a ReadSeeker, before dropping to the Reader part.

@rvagg
Copy link
Member

rvagg commented Oct 5, 2022

yeah, I think you're right, because the non-Reader case specifically offsets to 0, so we have a fork in behaviour if you give it a full Reader.. I suppose a case to check for a Seeker is in order, although I'm not really sure why the check for Reader even exists. Perhaps a potential optimisation? I wonder if we shouldn't just remove that and pass everything through the internalio.NewOffsetReadSeeker.

@masih @willscott any memories of why we might be special-casing a Reader here when we have a ReaderAt in our hands?

@willscott
Copy link
Member

the unwrapping / wrapping is mostly there for handling streaming use cases - if we're getting a car inbound as a reader over the network we want to be wrapping/unwrapping it such that we are pulling from the underlying buffer as we get the data.

@masih
Copy link
Member

masih commented Oct 6, 2022

+1 for consistency in behaviour; thank you for pointing this out.

@rvagg
Copy link
Member

rvagg commented Oct 8, 2022

I'm not sure I fully understand this, I wouldn't expect ReaderAt and ReadSeekerAt to be interfaces that you'd get if you were streaming a CAR. I'm probably missing something about the scope of "streaming" APIs in Go.

In terms of next steps, we could add a check for a Seeker and do a seek on that, but the confusing bit for me is that we're requiring a ReaderAt, coming in via NewReadOnly(). Are we really going to have a streaming CAR come in that's both a ReaderAt and a Reader? Why can't we just ditch the check for Reader entirely and use NewOffsetReadSeeker for all cases on the ReaderAt?

@BigLep BigLep added the P2 Medium: Good to have, but can wait until someone steps up label May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Medium: Good to have, but can wait until someone steps up
Projects
None yet
Development

No branches or pull requests

5 participants