kubernetes-client / csharp

Officially supported dotnet Kubernetes Client library
Apache License 2.0
1.09k stars 294 forks source link

Lock usage of YamlDotNet Serializer and Deserializer #1544

Closed alxmitch closed 5 months ago

alxmitch commented 6 months ago

YamlDotNet ISerializer / IDeserializer is not thread safe. This PR prevents concurrent use of the static serializers and deserializer in KubernetesYaml.

Addresses https://github.com/kubernetes-client/csharp/issues/1537

I have verified locally that this resolves the failing test in the linked PoC for the original issue, but have not included that test here as it didn't always reliably reproduce the issue. Keen for advice on appropriate testing around this change.

linux-foundation-easycla[bot] commented 6 months ago

CLA Signed

The committers listed above are authorized under a signed CLA.

k8s-ci-robot commented 6 months ago

Welcome @alxmitch!

It looks like this is your first PR to kubernetes-client/csharp 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/csharp has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. :smiley:

codecov-commenter commented 6 months ago

Codecov Report

Attention: Patch coverage is 90.00000% with 2 lines in your changes are missing coverage. Please review.

:exclamation: No coverage uploaded for pull request base (master@d523291). Click here to learn what that means.

Files Patch % Lines
src/KubernetesClient/KubernetesYaml.cs 90.00% 2 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1544 +/- ## ========================================= Coverage ? 61.46% ========================================= Files ? 103 Lines ? 3065 Branches ? 637 ========================================= Hits ? 1884 Misses ? 1181 Partials ? 0 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

tg123 commented 5 months ago

/LGTM

k8s-ci-robot commented 5 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alxmitch, tg123

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/kubernetes-client/csharp/blob/master/OWNERS)~~ [tg123] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
leonard520 commented 5 months ago

Hi, I am hitting the issue in our environment, and it is great to see the fix. May I know when will be a new release to include this fix? Thanks!

tg123 commented 5 months ago

13.0.37 is now published

shenglol commented 4 months ago

I'm curious, why did we opt for lock instead of ThreadLocal? We're using this library within an ASP.NET Core service that handles concurrent requests. The concern with lock is the potential performance overhead it introduces.

tg123 commented 4 months ago

@shenglol for now, it is a quick, dirty and safest solution.

could you please send a pr of suggesting optimization?