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

gateway: fix seeker can't seek on specific files #4320

Merged
merged 4 commits into from
Oct 20, 2017

Conversation

magik6k
Copy link
Member

@magik6k magik6k commented Oct 18, 2017

Fixes #4286

This is the somewhat hacky approach, but it is still way better (IMO) than rewriting http.ServeContent just to support that one case.

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
@ghost ghost assigned magik6k Oct 18, 2017
@ghost ghost added the status/in-progress In progress label Oct 18, 2017
@mib-kd743naq
Copy link
Contributor

way better (IMO) than rewriting http.ServeContent just to support that one case.

@magik6k my understanding of @whyrusleeping's #4286 (comment) is that aside from "that one case", the way we are using the HTTP server has non-trivial performance implications ( iiuc responses essentially can't be streamed until the entire DAG is enumerated ).

If the above is correct I much rather wait for the proper fix, than having a workaround go into go-ipfs, precluding time being allocated to fix the real problem :/

@magik6k
Copy link
Member Author

magik6k commented Oct 18, 2017

That is correct, the simplest solution here would be to just trust dr.pbdata.GetFilesize -
https://github.com/ipfs/go-ipfs/pull/4320/files#diff-e2e926fd88d79858d19deb317a28cb7bR245 in providing accurate file size. Looking at http lib internals it shouldn't open up any memory-exhaustion-DOS scenarios.

I'll commit that version of the fix soon

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
@magik6k
Copy link
Member Author

magik6k commented Oct 18, 2017

So this PR now does few things:

  • Makes gateway use custom seeker which uses Size method from reader when Seek is called with io.SeekEnd, this way we don't need to iterate large part of the dag to start getting blocks. It also fixes The problem with unset subnode sizes
  • Makes pbDagReader seek do nothing when it doesn't really need to
  • Makes merkledag.dedupeKeys return keys in correct order

With these changes large files start downloading immediately after first block is found and are streamed without randomly hanging on blocks that would be downloaded last.

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
return s.sizeReadSeeker.Seek(offset, whence)
}

func (i *gatewayHandler) serverFile(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, content io.ReadSeeker) {
Copy link
Member

Choose a reason for hiding this comment

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

s/serverFile/serveFile/


// If http.ServeContent can't figure out content size it won't write it to the
// responseWriter, Content-Length not being set is a good indicator of this
if req.Method != "HEAD" && w.Header().Get("Content-Length") == "" {
Copy link
Member

Choose a reason for hiding this comment

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

This feels hacky. I think in this case, ServeContent will have already written an error status and message to the responsewriter.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was here before sizeReadSeeker, isn't useful now (maybe as a fallback.. removing for now)

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
@whyrusleeping
Copy link
Member

@mib-kd743naq want to confirm that this works for you?

@mib-kd743naq
Copy link
Contributor

@whyrusleeping I won't be able to build a local web gateway for about couple days. But if I do my entire test will consist of firing up a gateway, and making sure I can open each file in https://ipfs.io/ipfs/QmZL4wivfYBEUutxksKgbpPfFkj1tGNMESYLFF2MWcST8Y/Last entry in this subdir errors on latest go-ipfs

So if one of you can validate this faster and it works: I am happy ;)

@whyrusleeping
Copy link
Member

@mib-kd743naq alright, i'll give it a try!

@whyrusleeping
Copy link
Member

Appears to work over here (tested via curl)

@whyrusleeping whyrusleeping merged commit 005d243 into master Oct 20, 2017
@ghost ghost removed the status/in-progress In progress label Oct 20, 2017
@whyrusleeping whyrusleeping deleted the fix/gateway-seeker branch October 20, 2017 12:15
@magik6k magik6k restored the fix/gateway-seeker branch November 27, 2017 03:34
@magik6k magik6k deleted the fix/gateway-seeker branch November 27, 2017 03:48
ariescodescream pushed a commit to ariescodescream/go-ipfs that referenced this pull request Apr 7, 2022
gateway: fix seeker can't seek on specific files
hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 27, 2023
gateway: fix seeker can't seek on specific files

This commit was moved from ipfs/kubo@005d243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants