Core: Handles possible heap data corruption of OAuth2Util.AuthSession#headers#10615
Conversation
| .tokenType(response.issuedTokenType()) | ||
| .build(); | ||
| this.headers = RESTUtil.merge(headers, authHeaders(config.token())); | ||
| synchronized (lock) { |
There was a problem hiding this comment.
Maybe just a simple
| synchronized (lock) { | |
| synchronized (this) { |
?
There was a problem hiding this comment.
TBH I'm not convinced that a lock solves a real problem. In practice, this method cannot be called concurrently, therefore just dissociating reading the field and writing the field back is enough to clarify the intents here:
Map<String, String> headers = this.headers;
this.headers = RESTUtil.merge(headers, authHeaders(config.token()));There was a problem hiding this comment.
@snazy @adutra thanks so much for reviewing
Maybe just a simple?
@snazy I just wanna avoid using synchronized on class. See: https://stackoverflow.com/questions/442564/avoid-synchronizedthis-in-java
TBH I'm not convinced that a lock solves a real problem. In practice, this method cannot be called concurrently, therefore just dissociating reading the field and writing the field back is enough to clarify the intents here:
@adutra "this method cannot be called concurrently" - could you explain why, pls? The RESTUtil.merge(...) function read a volatile variable (headers), so I think synchronized might make sense here.
|
@tlm365
|
There was a problem hiding this comment.
I agree with @adutra , I don't think a lock is necessary here. You can just read the volatile value into a temporary variable and use that temporary variable when merging and assign that to the field.
|
@adutra @amogh-jahagirdar thanks for reviewing, I've updated it. |
…#headers Signed-off-by: Tai Le Manh <manhtai.lmt@gmail.com>
amogh-jahagirdar
left a comment
There was a problem hiding this comment.
Thanks @tlm365 I will merge when checks pass.
…headers (apache#10615) Signed-off-by: Tai Le Manh <manhtai.lmt@gmail.com>
…headers (apache#10615) Signed-off-by: Tai Le Manh <manhtai.lmt@gmail.com>
Closes #10591.