kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
141 stars 45 forks source link

How can I detect that API server is disconnected while using watch function? #202

Closed clearday4 closed 3 months ago

clearday4 commented 10 months ago

Hello

I'd like to distinguish between no events from the API server during the watch behavior and a disconnected libcurl. If the API server is disconnected, I have to re-run the watch function.

In the current code, the only way to perform a periodic watch with a timeout, which means that I'll not receive notification from the API server for a worst-case timeout. I was hoping you could help me figure out what to do fix this.

Thanks in advance.

brendandburns commented 10 months ago

That's the only way to do it, since no data is sent if there are no events, the only other way to detect it is via a TCP timeout, but that's not currently supported.

We could consider adding support for that via: https://curl.se/libcurl/c/CURLOPT_TCP_KEEPALIVE.html

cc @ityuhui

clearday4 commented 10 months ago

my questions are as follows. If I call the API with watch option, curl_easy_perform should have already returned, so how do I know that the TCP connection has been lost? If I could know by the result of curl_easy_perform(), it doesn't make sense for the watch behavior. I think I need to check via callback function. Is it possible to check if TCP is disconnected using CURLOPT_XFERINFOFUNCTION?

ityuhui commented 9 months ago

We already support CURLOPT_XFERINFOFUNCTION via progress_func

https://github.com/kubernetes-client/c/blob/0f0f4cc228415b80889f640b7ac2967dc09bbec5/kubernetes/include/apiClient.h#L28

You can have a try.

k8s-triage-robot commented 5 months ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 4 months ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot commented 3 months ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-ci-robot commented 3 months ago

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to [this](https://github.com/kubernetes-client/c/issues/202#issuecomment-2024293333): >The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. > >This bot triages issues according to the following rules: >- After 90d of inactivity, `lifecycle/stale` is applied >- After 30d of inactivity since `lifecycle/stale` was applied, `lifecycle/rotten` is applied >- After 30d of inactivity since `lifecycle/rotten` was applied, the issue is closed > >You can: >- Reopen this issue with `/reopen` >- Mark this issue as fresh with `/remove-lifecycle rotten` >- Offer to help out with [Issue Triage][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.