-
Notifications
You must be signed in to change notification settings - Fork 66
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 determine if a given line is complete or not #25
Comments
Thank you @kokes! I will review the proposed changes as soon as possible and ask you if needed for a PRs. If people have options about this issue, feel free to comment here. |
@nxadm thanks for the prompt reply, I have three bits of news:
|
So I looked into it a little more and got stuck. Even with my newline implementation, I get issues with properly buffering partial lines and it's getting a bit yucky. Also, I'm not sure if the reader should be handling all this. I got to the following:
The line number there is to keep the buffer relevant only for that line and nothing else (to prevent issues during reopens). But it turns out I can't use this, because the I tried fiddling with the lineNum counter, but it just made the code messier and messier. I'm starting to thing this partial line business will be a bit more complex than anticipated. |
Upon further reflections (and failing to implement a working solution on top of the library), I decided to rework it in a different branch, this time giving the user an extra knob to enable this new functionality. This should be fully backwards compatible - all the tests pass, the new functionality is behind a boolean check, though I did simplify the err handling a bit, specifically this chunk seemed repetitive - we can trim the newline in case of error, it won't be there anyway. Everything else stays the same, there's a new private struct member to buffer incomplete lines and new tests pass. Last but not least - there's a bit of data loss if a given file never ends with a new line. This shouldn't hang in case of truncations, but I'll check the PRs I linked above to see if I introduced a regression. Edit: Oh and there's something I discovered looking through the past PRs - even if we set This might be a bit controversial, so feel free to suggest reverting this. |
@nxadm having run this in our pre-production setting for the past 10 days or so (works well), I decided to submit a PR. I only used the latter approach, I found the earlier suggestion (the one with EOL markers) to be pretty hard to reason about from a user's perspective. |
Great to hear. Just a message to let you know I am not ignoring the issue, just a little busy at the moment. Your effort is appreciated! |
Now that I preparing the release of 1.4.9/1.5.0 (in case we include the PR), I had a look at the PR. Good job. I had few remarks/questions does:
But again, the main question is the first one. Any ideas on the balance between the added configuration and generality of the use case? ping @dolmen, @42wim |
@nxadm Note that the buffer is NOT filled in the default case (CompleteLines: false). The buffer is only used when CompleteLines is set to true - I accepted your change request and will only allocate the buffer in that case... but it shouldn't really make much of a difference. See kokes@2241350 |
I merged the PR, thank you. I am waiting on fsnotify for creating a new release. In the meantime, please keep testing it :) |
@nxadm not sure if that's coming - fsnotify hasn't had a code/dependency change commited since the last release, so I wouldn't expect it anytime soon. |
Cool, thanks! Need this feature in a project. |
@nxadm Hey! Thanks for all the work you've done on this, do you think there's any chance a new version could be tagged? fsnotify released 1.5.4 about a month ago |
I'll try to look this week for what's needing for making a release. At the latest, I'll release next week. Thank you for your patience. |
Working on the new release now and bumped fsnotiy. Checking what old bugs it fixes. |
Hey @nxadm - any news on the tagged release? 😄 I think we've started running into this as an occasional edge case within our infra, so it'd be great to pull the fix in. If you need any contributions to make it happen, then please do shout. Thanks again for all of your work on this super useful library! |
I also noticed that tailing occasionally gives incomplete lines 🤔 Probably the same problem. Is there any progress on this? 🤔 |
go to https://github.com/hpcloud/tail . I face the same problem. I find this repo meets your requirement . |
Describe the bug
There seems to be race condition that leads to partial line reads. That is, if a line write is not atomic, I can read a partial line, but since
tail
strips all newlines, I'll never know this happened. (My code will fail further on as it finds out said line is incomplete.)Expected behaviour
There are two ways this can be addressed:
line.Text
, this would be a breaking change, not really a good solutionNewlineEnding
toLine
, which would tell the reader if theline.Text
returned actually contained a newline at the end or not. This should be fully backwards compatible.Here's my locally tested patch (it's just a draft): kokes@519502e
To Reproduce
Write a simple tailer:
A cli wrapper for this library
And run this against a random text file,
go run repro.go tmp.log
and then write to it:This creates two lines, both containing
foofoo
, but we can't tell from the reader's point of view:System information
Additional context
This was reported back in 2014 in the original repo #35 and "fixed" without tests in #40, which deadlocked the process if the tailed file didn't end with a newline. It was then reverted in this repo by merging in #126.
My proposal doesn't affect the library's behaviour, just adds a flag to inform the user of partial rows. I wasn't super sure how to handle splitting or large lines, so please review my code.
The text was updated successfully, but these errors were encountered: