-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
8303809: Dispose context in SPNEGO NegotiatorImpl #12920
Conversation
👋 Welcome back abakhtin! A progress list of the required criteria for merging this PR into |
@alexeybakhtin The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wangweij it would be good if you (or someone from security libs) could review this PR too
if (context != null) { | ||
context.dispose(); | ||
} | ||
}catch (GSSException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trivially: please add space after }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Sure, I will fix
|
||
public void disposeContext() { | ||
// do nothing | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have some comment explaining the purpose of this method. In particular, it would be good to state when (at which point) it is supposed to be called.
Also hopefully the AuthenticationInfo
object remain valid and can still be used after disposeContext
has been called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, AuthenticationInfo
is still valid after disposeContext
.
The Negotiator with the new context will be recreated if required https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java#L224
/reviewers 2 reviewer |
I'm not familiar with this code and don't know how to execute it, but since you mentioned native memory leak... I'm assuming NativeGSSConext is the class that holds a reference to the native memory. The class has a cleaner that is supposed to release the memory. It was recently refactored in JDK-8284490, and I think this refactoring introduced the leak. See: In general, when fixing native memory leaks, please focus on fixing broken cleaners, rather than manually disposing the memory. |
@djelinski Not a cleaner or lambda export, when |
ah, you're right, But then, is there any other place where we could be leaking native memory? As far as I could tell, this patch only releases the memory earlier, it doesn't fix any leaks. Am I missing something? |
Maybe it's because it can be added into a cache or stored in |
My 2 cents: I think the change to This might not be perfect, for example, if the context is not established yet but for some reason the |
@dfunch, @djelinski, @wangweij Thank you a lot for review and suggestions. |
@alexeybakhtin thanks for adding more context. I believe @wangweij was suggesting adding |
If context is not established after first call to |
Yes, after both |
Unfortunately, there is no guarantee |
Yes, you are right. I believe the reason is that once an 200 OK is received, no one cares to look at the token anymore. |
disposeContext(); | ||
} catch(Exception ex) { | ||
//dispose context silently | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this cleanup necessary here but not in nextToken()
? If we don't do any cleanup here, will disposeContext()
be called inside HttpURLConnection
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GSSContext could be allocated in init() line 97 but fails with Exception in context.initSecContext(). In this case null Negotiator is returned https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/sun/net/www/protocol/http/Negotiator.java#L71 to NegotiatorAuthenticator: https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/sun/net/www/protocol/http/NegotiateAuthentication.java#L224. So nobody can clean context from HttpURLConnection
if (negotiator != null) { | ||
try { | ||
negotiator.disposeContext(); | ||
}catch(IOException ioEx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a space before catch
.
@@ -251,7 +251,7 @@ public void disposeContext() { | |||
if (negotiator != null) { | |||
try { | |||
negotiator.disposeContext(); | |||
}catch(IOException ioEx) { | |||
} catch(IOException ioEx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another whitespace is required after catch
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Fixed
Hi @alexeybakhtin, I will do some tests and come back to you here. |
@@ -82,5 +82,7 @@ private static void finest(Exception e) { | |||
logger.finest("NegotiateAuthentication: " + e); | |||
} | |||
} | |||
|
|||
public abstract void disposeContext() throws IOException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have some old internal tests that extend Negotiator
and that will fail when this change is pushed. I'd suggest to change this method as follows:
public abstract void disposeContext() throws IOException; | |
public void disposeContext() throws IOException { } |
This should avoid breaking existing subclasses that do not implement this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Changed from abstract to empty.
sun/security/jgss sun/security/krb5 sun/net/www/protocol/http tests passed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Alexey. Tests returned green. Good to go!
Thank you a lot for review |
@alexeybakhtin This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 92 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
Going to push as commit 10f1674.
Your commit was automatically rebased without conflicts. |
@alexeybakhtin Pushed as commit 10f1674. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
This patch fixes a possible native memory leak in case of a custom native GSS provider.
The actual leak was reported in production.
sun/security/jgss, sun/security/krb5, sun/net/www/protocol/http jtreg tests are passed
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/12920/head:pull/12920
$ git checkout pull/12920
Update a local copy of the PR:
$ git checkout pull/12920
$ git pull https://git.openjdk.org/jdk pull/12920/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 12920
View PR using the GUI difftool:
$ git pr show -t 12920
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/12920.diff