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

Cannot camput bytes - get Unexpected EOF error #642

Closed
dbp opened this issue Oct 2, 2015 · 22 comments
Closed

Cannot camput bytes - get Unexpected EOF error #642

dbp opened this issue Oct 2, 2015 · 22 comments

Comments

@dbp
Copy link

dbp commented Oct 2, 2015

I see an old, fixed issue (#4) that says that there used to be an issue where files without linefeeds would trigger this error. I'm not sure if it's the same issue (I see this error both with 0.8 and HEAD, built with go 1.5.1 on mac), but trying to add a blob with the contents at http://s3.dbp.io/misc/camli-eof-2015-10-2 (I'm not sure what this is - it came out of another camliserver, presumably it is a part of an image) causes the following error on the server:

2015/10/02 11:24:59 Removing temp file:  /Users/dbp/Library/Camlistore/blobs/sha1/0b/02/sha1-0b02b0a54c5ee9cb0d261331bc12ce9c45923d07.dat.tmp280630491
2015/10/02 11:24:59 Client error: Error receiving blob sha1-0b02b0a54c5ee9cb0d261331bc12ce9c45923d07: unexpected EOF

and correspondingly on the client:

2015/10/02 11:32:02 Error putting blob: Server didn't receive blob.

I noticed this error because I was trying to sync from a blobserver on another computer to this one, and I was getting lots of these errors in syncing (and the result of the sync was messed up - lots of permanodes with no claims, etc). So I grabbed one sha (to try to figure out what went wrong), and checked and it existed on the old server, and I could camget it, which is where the file I linked to above came from. But trying to camput blob it causes the above error.

@mpl
Copy link
Contributor

mpl commented Oct 2, 2015

I haven't checked yet, but the .tmpxxx suffix suggests me that it could be an incomplete blob, hence the error ?

@dbp
Copy link
Author

dbp commented Oct 2, 2015

@mpl What does an incomplete blob mean? I thought a blob was just bytes - shouldn't I be able to camput blob anything?

@mpl
Copy link
Contributor

mpl commented Oct 2, 2015

@dbp disregard that last comment, lemme look into it.

Still, camput blob is not meant to do what I'm guessing you want to do here.
camput blob takes a file, which will be broken into blobs. Whereas I'm guessing you're trying to just give that blob so it gets as is into the blobserver, which I don't think can happen with camput blob.
You'd rather want to use something like camtool sync in that case.

Regardless, you're right that you should be able to give any file to camput blob without crashing it. It's somewhat similar to issue #248

@dbp
Copy link
Author

dbp commented Oct 2, 2015

Just to follow up a little - I did a little digging (I've never written any Go code, so forgive any silly misunderstandings). I tracked the error down to happening within the call to copy into the tempfile here:

https://github.com/camlistore/camlistore/blob/9106ce829629773474c689b34aacd7d3aaa99426/pkg/blobserver/localdisk/receive.go#L53

Looking at the stack at that point, in order to figure out what Reader was being used (as I'm assuming the TempFile writer works!), it looks like Receive is being called here:

https://github.com/camlistore/camlistore/blob/9106ce829629773474c689b34aacd7d3aaa99426/pkg/blobserver/handlers/upload.go#L226

Which means the reader is a few wrappers around the mime/multipart reader that is returned from NextPart here:

https://github.com/camlistore/camlistore/blob/9106ce829629773474c689b34aacd7d3aaa99426/pkg/blobserver/handlers/upload.go#L197

This is starting to sound suspiciously like issue #4.... Or maybe some new variant of it (it looks like the unexpected EOF error is coming from the mime/multipart library, but obviously that doesn't mean there is a bug there - it could be camlistore's encoding that is the culprit).

I don't understand multipart encoding well, so I'm not sure if I'll be able to make much sense out of what is wrong, but by setting CAMLI_DEBUG_UPLOADS=1 on the camput command, I could see that it goes through code here:

https://github.com/camlistore/camlistore/blob/9106ce829629773474c689b34aacd7d3aaa99426/pkg/client/upload.go#L425

And then errors out at the end of that function.

@mpl
Copy link
Contributor

mpl commented Oct 2, 2015

yes, I arrived to the same suspicions. I'm investigating the stdlib.

@mpl
Copy link
Contributor

mpl commented Oct 4, 2015

I believe I found the bug, see:
https://go-review.googlesource.com/15269

@mpl mpl added the accepted label Oct 4, 2015
@dbp
Copy link
Author

dbp commented Oct 4, 2015

@mpl Thanks!

@mpl
Copy link
Contributor

mpl commented Oct 5, 2015

@dbp thank you for reporting it.

bradfitz pushed a commit to golang/go that referenced this issue Oct 9, 2015
The case fixed by this change happens when, in func (pr partReader)
Read, the Peek happens to read so that peek looks like:

  "somedata\r\n--Boundary\r"

peekBufferSeparatorIndex was returning (-1, false) because it didn't
find the trailing '\n'.

This was wrong because:

1) It didn't match the documentation: as "\r\n--Boundary" was found, it
should return the index of that pattern, not -1.

2) It lead to an nCopy cut such as:
  "somedata\r| |\n--Boundary\r" instead of "somedata| |\r\n--Boundary\r"
which made the subsequent Read miss the boundary, and eventually end
with a "return 0, io.ErrUnexpectedEOF" case, as reported in:

perkeep/perkeep#642

Change-Id: I1ba78a741bc0c7719e160add9cca932d10f8a615
Reviewed-on: https://go-review.googlesource.com/15269
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
@mpl
Copy link
Contributor

mpl commented Oct 9, 2015

fixed at 821b54921a3cba5d853b531d4b03527c01bfc9b4 in Go tree.

@mpl mpl closed this as completed Oct 9, 2015
@bradfitz
Copy link
Contributor

bradfitz commented Oct 9, 2015

Wait, shouldn't we vendor mime/multipart into Camlistore for now?

And then open a "Things to fix in Camlistore when Go depends on Go 1.6" bug?

@bradfitz bradfitz reopened this Oct 9, 2015
@mpl
Copy link
Contributor

mpl commented Oct 9, 2015

ugh, yes, sorry. Since I've switched to gotip to fix that bug I had forgotten we're supposed to run on Go 1.5.

@mpl
Copy link
Contributor

mpl commented Oct 9, 2015

@bradfitz I'll confirm tomorrow the reason, but I'm having some trouble getting Camlistore to use the vendored version.

I can confirm that I vendored it properly because when I add a dummy var to the source of the vendored code, I can set/access that dummy var, say in camlistored.go (and adding a "mime/multipart" import in camlistored.go).

However, it seems like, since in pkg/blobserver/handlers/upload.go we don't use the multipart pkg directly, but we instead get a Reader through "multipart, err := req.MultipartReader()", in that case we get the buggy code from Go 1.5, because req from net/http was built against the mime/multipart of Go 1.5. At least that's my suspicion.

@mpl
Copy link
Contributor

mpl commented Oct 12, 2015

@bradfitz I think I was able to confirm my suspicion above, i.e. that since we're getting the multipart Reader from net/http, we're getting the (buggy) one from Go 1.5.

Suggestion? We don't want to vendor net/http as well now, do we ?

@bradfitz
Copy link
Contributor

Oh, I see. Gross.

@bradfitz
Copy link
Contributor

I flagged the issue as a potential Go 1.5.2 backport. We'll see how others feel.

@sherter
Copy link

sherter commented Oct 13, 2015

So we have to wait for Go 1.5.2? No other workaround possible? In this state camlistore is pretty useless to me...

@mpl
Copy link
Contributor

mpl commented Oct 13, 2015

@sherter uh, just use go tip ? Or even easier, just patch your Go 1.5 source tree as in https://go-review.googlesource.com/15269 ; it's a 3 chars fix...

Also, I don't think the odds of hitting that bug are very large, as it requires a file of a very specific size. You could just not upload such files if that occurs.

@dbp
Copy link
Author

dbp commented Oct 13, 2015

I hit this many times when trying to sync between camlistore servers (I
just included one example in the issue), so I feel like it's not that
unlikely (or I'm very unlucky)...

On Tuesday, October 13, 2015, mpl notifications@github.com wrote:

@sherter https://github.com/sherter uh, just use go tip ? Or even
easier, just patch your Go 1.5 source tree as in
https://go-review.googlesource.com/15269 ; it's a 3 chars fix...

Also, I don't think the odds of hitting that bug are very large, as it
requires a file of a very specific size. You could just not upload such
files if that occurs.


Reply to this email directly or view it on GitHub
#642 (comment)
.

@mpl
Copy link
Contributor

mpl commented Oct 13, 2015

Fair enough. But my first suggestions still stand :-)

@dbp
Copy link
Author

dbp commented Oct 13, 2015

@mpl Definitely. And it's also perfectly usable for me. I just have to use just one server :)

@mpl
Copy link
Contributor

mpl commented Oct 13, 2015

@mpl mpl mentioned this issue Oct 14, 2015
@mpl
Copy link
Contributor

mpl commented Oct 14, 2015

afe28eb
666d525

@mpl mpl closed this as completed Oct 14, 2015
mpl added a commit to mpl/perkeep that referenced this issue Oct 16, 2015
At a2119aca7dc82dc5b5cd40b1a2f56e82323da002 in go tip
because we want the bugfix at 821b54921a3cba5d853b531d4b03527c01bfc9b4

We could legitimately vendor as "vendor/mime/multipart" and shadow the
stdlib's but we do it in future for clarity.

Issue perkeep#642

Change-Id: Ifddbd4c9120936b8acc2f6ae31a97b1831b99f34
mpl added a commit to mpl/perkeep that referenced this issue Oct 16, 2015
…rt Reader

We redefine a MultipartReader(*http.Request) function to use instead of
req.MultipartReader, so we can get a (bugfixed) multipart Reader from
our vendored mime/multipart, instead of the buggy one from the stdlib's.

Fixes issue perkeep#642

Change-Id: I6a205bff915632d4ee77547e6e26bc0af99665e9
stevearm pushed a commit to stevearm/perkeep that referenced this issue Mar 6, 2016
revert changes afe28eb and
666d525 because Go 1.6 is out.

Issues perkeep#642 and perkeep#644

Change-Id: Ide422b5164576c77d72061bb05ea0984c68d55e4
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

No branches or pull requests

4 participants