Skip to content
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

Thread safe improvements on OIDCDiscoveryConfigListener #4159

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

matzew
Copy link
Contributor

@matzew matzew commented Nov 6, 2024

Proposed Changes

  • using ConcurrentHashMap, AtomicRef and AtomicInt for improving thread safeness

Release Note


Docs

@knative-prow knative-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/data-plane labels Nov 6, 2024
@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 6, 2024
Copy link

codecov bot commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 45.51%. Comparing base (716759f) to head (9959d01).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4159   +/-   ##
=======================================
  Coverage   45.51%   45.51%           
=======================================
  Files         270      270           
  Lines       19925    19925           
=======================================
  Hits         9069     9069           
  Misses      10129    10129           
  Partials      727      727           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Matthias Wessendorf <[email protected]>
@knative-prow knative-prow bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 6, 2024
.forEach(c -> c.accept(this.oidcDiscoveryConfig));
OIDCDiscoveryConfig config = this.oidcDiscoveryConfig.get();
if (config != null) {
this.callbacks.forEach(callback -> callback.accept(config));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see in deregisterCallback we set callback (the element) to null, don't we need to check that callback is not null before calling accept ?

@knative-prow knative-prow bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 6, 2024
this.callbacks = new ArrayList<>();
}

public synchronized int registerCallback(Consumer<OIDCDiscoveryConfig> callback) {
Copy link
Member

@pierDipi pierDipi Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other issue I see with index based registration is that with addition and removal of callbacks the array is ever growing (and therefore a memory leak), which can lead to OOM, it's better to have a map id -> callback so that we can remove elements during registration rather than setting them to null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean like ConcurrentMap ? instead of the CopyOnWriteArrayList?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Nov 6, 2024
Copy link

knative-prow bot commented Nov 6, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: matzew, pierDipi

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:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@matzew
Copy link
Contributor Author

matzew commented Nov 6, 2024

/cherry-pick release-1.16

@knative-prow-robot
Copy link
Contributor

@matzew: once the present PR merges, I will cherry-pick it on top of release-1.16 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.16

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@matzew
Copy link
Contributor Author

matzew commented Nov 6, 2024

/cherry-pick release-1.15

@knative-prow-robot
Copy link
Contributor

@matzew: once the present PR merges, I will cherry-pick it on top of release-1.15 in a new PR and assign it to you.

In response to this:

/cherry-pick release-1.15

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@creydr
Copy link
Contributor

creydr commented Nov 6, 2024

/retest

@knative-prow knative-prow bot merged commit 6206167 into knative-extensions:main Nov 6, 2024
33 checks passed
@knative-prow-robot
Copy link
Contributor

@matzew: new pull request created: #4160

In response to this:

/cherry-pick release-1.16

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@knative-prow-robot
Copy link
Contributor

@matzew: new pull request created: #4161

In response to this:

/cherry-pick release-1.15

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/data-plane lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants