-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Truncating an MFS file 175 times makes it unwritable. #4519
Comments
Test case: func TestTruncateAndWrite(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ds, rt := setupRoot(ctx, t)
dir := rt.GetValue().(*Directory)
nd := dag.NodeWithData(ft.FilePBData(nil, 0))
fi, err := NewFile("test", nd, dir, ds)
if err != nil {
t.Fatal(err)
}
fd, err := fi.Open(OpenReadWrite, true)
defer fd.Close()
if err != nil {
t.Fatal(err)
}
for i := 0; i < 200; i++ {
err = fd.Truncate(0)
if err != nil {
t.Fatal(err)
}
l, err := fd.Write([]byte("test"))
if err != nil {
t.Fatal(err)
}
if l != len("test") {
t.Fatal("incorrect write length")
}
data, err := ioutil.ReadAll(fd)
if err != nil {
t.Fatal(err)
}
if string(data) != "test" {
t.Errorf("read error at read %d, read: %v", i, data)
}
}
} @whyrusleeping any ideas? |
tests #4519 License: MIT Signed-off-by: Steven Allen <[email protected]>
thats.... special |
@Stebalien Are you currently addressing this in your PR #4517? (I saw you were making fixes to the Truncating to any smaller than (the original) 4 bytes value produces the same error. Truncating to zero 174 times and the rest of the times to 1 produces:
Similarly, truncating to 2:
The same progression continues truncating to 3. I'm avoiding truncating to the same size for the error you encountered and fixed. Truncating to 5 or bigger (always starting with 174 truncations to zero) only fails in iteration 175:
Truncating from the start to a value bigger than 4 panics:
But the last two cases may be more related with a problem in |
@Stebalien I took another look at this (sorry if I jumped the gun here, I don't know if you were currently working on it) and the main issue seems to be that I'm new to IPFS and there aren't a lot of comments in the code for a beginner like me to clearly determine what is the expected behavior of some parts of it, so I document here what has drawn my attention while debugging this issue, and leave it to a more experienced developer to determine if there are any problems (beyond the one already mentioned). After each write to the test file a new node is added ( In this test iteration 175, while reading the file ( In every write of the test a new In parallel to all this The function |
@schomatis wow 👏👏👏👏👏👏👏👏👏👏👏👏👏 Great sleuthing work. I'm sorry for writing crappy undocumented code. So a bit of unix weirdness, truncating a file does not reset its current position (see https://golang.org/pkg/os/#File.Truncate). So that bit of the behaviour is correct, weirdness comes from a couple things i think:
I don't believe that @Stebalien is actively working on this one, so its all yours. Thank you for investigating :) |
AWESOME work! I'm not currently working on this. Would you be up to reviving that PR (you'll probably need to make a new one based on a rebased |
@Stebalien Great, I'll give that a try and let you know. |
After exactly 175 truncate/writes, mfs returns an empty string from read (forever, apparently).
The text was updated successfully, but these errors were encountered: