-
Notifications
You must be signed in to change notification settings - Fork 291
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
Json errror in watch #828
Comments
did you catch what returned from server side? |
There is no chance to get it, the exception was thrown in internal code here https://github.com/kubernetes-client/csharp/blob/master/src/KubernetesClient/Watcher.cs#L191, so I guess it maybe an empty string. |
i believe it is something else like |
After further check the exception stack, the exception is thrown here: https://github.com/kubernetes-client/csharp/blob/master/src/KubernetesClient/Kubernetes.cs#L89, before the previous location. The exception only occur when nothing returned at all since watch request started. |
lets try to do wireshark or tcpdump to see if it is server side err |
I will do more tests soon. |
I figured out the problem, for the code csharp/src/KubernetesClient/Kubernetes.cs Lines 86 to 90 in 8cfe60b
When watch without any result, the request hang here util the api server close the connection, the json deserialize from empty stream will throw exception. Since the result.Body is not used in watch case, I think we can change to code to following to fix this issue
I have verified in local the watch works without json exception anymore. Another way to fix is change stream to string before json deserialize
|
the internal stream is replaced by checked code here
should throw EOF if null |
In the later code after the change I made, it gets string first before json deserialize, and return if string null, so the watch can finish without exception in watch no result case. csharp/src/KubernetesClient/Watcher.cs Lines 178 to 185 in 8cfe60b
|
please drop a PR |
I will create PR soon after I figure out another problem(watch hang in version 7.1+, 7.0.15 is ok). |
There are two way to avoid json deserialize error in following code while watch no result csharp/src/KubernetesClient/Kubernetes.cs Lines 83 to 90 in 199ec8b
@tg123 |
maybe to throw en eof exception at
when peekline === null, which means it is eof and nothing returned from server in the first line
|
If throw EOFException in LineSeparatedHttpContent, do you mean we catch EOFException like following
|
I think throw the exception, because the |
You mean throw the exception outside of KubernetesClient, the client which uses this library to handle exception, right? |
yes, the eof exception is far clear than json deserialize |
After throw EndOfStreamException in LineSeparatedHttpContent.SerializeToStreamAsync, the HttpContent encapsulate it to HttpRequestException, the exception stack looks like this, the client need to aware it from ex.InnerException, is it ok for you?
|
Thanks I am open to it any reason to wrap it with httprequestexception? |
It is HttpContent who wrap it, it is .net inner logic, because LineSeparatedHttpContent extends HttpContent. |
+1 make sense |
Verified in 7.2.19, I can better handle the exception with following code
|
The kubernetes API server closes watch connection after 30~60 minutes if nothing returned, in this case the client gets json deserialize error.
I am wondering if we can change the line https://github.com/kubernetes-client/csharp/blob/master/src/KubernetesClient/Watcher.cs#L182 from
line == null
tostring.IsNullOrEmpty(line)
to fix this.The full exception stack here:
The text was updated successfully, but these errors were encountered: