-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
LogWatch throws IOException #3636
Comments
If no output is provided to watchLog, the inputstream created will get auto-closed Line 67 in 67f04df
In the closure logic there is a flush - but that flush does not ensure the read side fully consumes the buffer, just that it wakes up if needed. So the subsequent close call then results in the exception you are seeing even with data still left to be read. I think the code should only close the PipedOutputStream, that will then give you an exception only once you've read all of the data. This is somewhat related to #3243 |
Thank you for the fast reply, is there something I can do right now to work around this? I also read the issue you linked and tried to adapt it for me but unfortunately I couldn't make it work. |
@cmdjulian I was thinking that you could take responsibility for the pipes:
Then it won't close the output. However I don't see that the LogWatch logic will call close on out at any point then - which seems like you'd have no good way to know if things failed prematurely. I think this implies we should close the out stream regardless of whether it is passed in or not. |
Yep it's like you said, when using the solution you propose I get an |
Yes, if you have the time, please open a pr. This is what I was thinking locally about simplifying the LogWatchCallback constructor to:
|
@cmdjulian let me know if you want me to submit a pr instead. @rohanKanojia are you okay with closing the passed in OutputStream? At the very least that would need a javadoc and probably called out in the changelog. Or do you want that to be specific to only when out is an instanceof PipedOutputStream? |
Would be nice if you could open the pr @shawkins, thanks |
the inputstream is not directly closed, as that leads to data loss the outputstream is closed when it's piped so that the connected stream sees eof
Describe the bug
In versions prior to version
5.0.0
especially4.13.3
the following code works fine collecting and printing logs:After the latest update from Spring which is now using
KubernetesClient 5.9.0
under the hood I'm getting the error attached at the bottomThe problem is not the Exception, the problem lays in when the Exception occurs. it is thrown very unpredictable. I always results in loss of log lines so its not thrown at the end of the pipe getting closed.
Sometimes a few lines from the beginning are missing, sometimes a few lines at the end are missing and sometimes it even crashes directly after the first readLine occurred and returning zero read lines.
If I have long running Jobs the problem doesn't occur, it only occurs with Jobs lasting only 1 to 2 seconds.
Before calling the LogWatch I make sure that the Pod of the Job is running because when I don't do that I get an error that the Pod is not ready for log extraction. If I use the
withLogWaitTimeout(5000)
method the Job is maybe alreadyfailed
and therefore the method is never actually reaching the pod success state and always is running in the timeout.If I screwed up here and there is a better way to achieve that please let me now.
What I need is waiting before the Job Pod gets ready --> stream logs (all logs line by line) and return from the method if the pod terminates --> extract exit code.
I tried it with the latest version as well with the same outcome.
Fabric8 Kubernetes Client version
5.10.1@latest
Steps to reproduce
Run Job in Kubernetes with a runtime of one to two seconds and see the log watch failing
Expected behavior
Same behavior as in version
4.13.0
.Just returning
null
if the stream is closed and don't throw an IOException.Runtime
other (please specify in additional context)
Kubernetes API Server version
1.21.6
Environment
Linux
Fabric8 Kubernetes Client Logs
Additional context
Kubernetes:
k3s
The text was updated successfully, but these errors were encountered: