I don't see how this change would help. The call that crashes Eclipse is
Secur32.INSTANCE.FreeCredentialsHandle(clientCred);
which never returns.
It crashes only when the call is made from inside GC when garbage collection is
in progress. I am wondering if this has anything to do with threading. Wild
guess.
For right now I have extended the WindowsNegotiateSchemeFactory to hold all the
references to created WindowsNegotiateScheme's until my client is closed. This
way they are not garbage-collected, but this is obviously not the proper way to
handle these things.
From: Gary Gregory <[email protected]>
To: HttpClient User Discussion <[email protected]>; Alexander
Bernstein <[email protected]>
Sent: Thursday, August 27, 2015 12:58 PM
Subject: Re: GPF in WindowsNegotiateScheme.dispose()
I'm wondering if WindowsNegotiateScheme.dispose() should be more defensive.
But how? We now have:
public void dispose() {
if (clientCred != null && !clientCred.isNull()) {
final int rc =
Secur32.INSTANCE.FreeCredentialsHandle(clientCred); // BOMBS HERE
if (WinError.SEC_E_OK != rc) {
throw new Win32Exception(rc);
}
}
if (sspiContext != null && !sspiContext.isNull()) {
final int rc =
Secur32.INSTANCE.DeleteSecurityContext(sspiContext);
if (WinError.SEC_E_OK != rc) {
throw new Win32Exception(rc);
}
}
continueNeeded = true; // waiting
clientCred = null;
sspiContext = null;
}
Maybe this would help in some edge cases:
Index:
src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java
===================================================================
--- src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java
(revision
1698005)
+++ src/main/java/org/apache/http/impl/auth/win/WindowsNegotiateScheme.java
(working
copy)
@@ -97,6 +97,7 @@
public void dispose() {
if (clientCred != null && !clientCred.isNull()) {
final int rc =
Secur32.INSTANCE.FreeCredentialsHandle(clientCred);
+ clientCred = null;
if (WinError.SEC_E_OK != rc) {
throw new Win32Exception(rc);
}
@@ -103,6 +104,7 @@
}
if (sspiContext != null && !sspiContext.isNull()) {
final int rc =
Secur32.INSTANCE.DeleteSecurityContext(sspiContext);
+ sspiContext = null;
if (WinError.SEC_E_OK != rc) {
throw new Win32Exception(rc);
}
?
Gary
On Wed, Aug 26, 2015 at 1:07 PM, Alexander Bernstein <
[email protected]> wrote:
> Hello,
> I am new here, please pardon if this is not the right place for this kind
> of question.
> I am using httpclient-win-4.5 from httpClient 4.5 and
> jna-4.1.0/jna-platform-4.1.0 JNA libraries to authenticate to Kerberos
> server from Eclipse-based application.
> I create my client from WinHttpClients.custom(). The authentication is
> successful, but sooner or later, when JVM calls
> WindowsNegotiateScheme.dispose() my Eclipse crashes with GPF.
> I noticed that WindowsNegotiateSchemeFactory.create() is called twice, for
> some reason. Not sure if this is a normal flow and/or is relevant to the
> problem.
>
> 1XMCURTHDINFO Current thread
> NULL ----------------------
> 3XMTHREADINFO "Finalizer thread" J9VMThread:0x0000000003FD1B00,
> j9thread_t:0x00000000050C1F10, java/lang/Thread:0x000007FFDE5E2800,
> state:R, prio=5
> 3XMJAVALTHREAD (java/lang/Thread getId:0x15, isDaemon:true)
> 3XMTHREADINFO1 (native thread ID:0xCBC, native priority:0x5,
> native policy:UNKNOWN, vmstate:R, vm thread flags:0x00000000)
> 3XMTHREADINFO3 Java callstack:
> 4XESTACKTRACE at com/sun/jna/Native.setPointer(Native
> Method)
> 4XESTACKTRACE at
> com/sun/jna/Pointer.setPointer(Pointer.java:1195)
> 4XESTACKTRACE at
> com/sun/jna/Memory.setPointer(Memory.java:658)
> 4XESTACKTRACE at
> com/sun/jna/Pointer.setValue(Pointer.java:937)
> 4XESTACKTRACE at
> com/sun/jna/Structure.writeField(Structure.java:800)
> 4XESTACKTRACE at
> com/sun/jna/Structure.write(Structure.java:718(Compiled Code))
> 4XESTACKTRACE at
> com/sun/jna/Structure.autoWrite(Structure.java:1923(Compiled Code))
> 4XESTACKTRACE at
> com/sun/jna/Function.convertArgument(Function.java:505(Compiled Code))
> 4XESTACKTRACE at
> com/sun/jna/Function.invoke(Function.java:297(Compiled Code))
> 4XESTACKTRACE at
> com/sun/jna/Library$Handler.invoke(Library.java:212)
> 4XESTACKTRACE at
> com/sun/proxy/$Proxy13.FreeCredentialsHandle(Bytecode PC:18)
> 4XESTACKTRACE at
> org/apache/http/impl/auth/win/WindowsNegotiateScheme.dispose(WindowsNegotiateScheme.java:99)
> 4XESTACKTRACE at
> org/apache/http/impl/auth/win/WindowsNegotiateScheme.finalize(WindowsNegotiateScheme.java:117)
> 4XESTACKTRACE at
> java/lang/J9VMInternals.runFinalize(J9VMInternals.java:436)
> 3XMTHREADINFO3 No native callstack available on this platform
> NULL
> Appreciate any help and suggestions.Thank you
> Alex Bernstein
--
E-Mail: [email protected] | [email protected]
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory