B4J Question [Solved] javax.net.ssl.SSLHandshakeException

bdunkleysmith

Active Member
Licensed User
Longtime User
I have a couple of B4J applications which have operated without error for several years and which include

B4X:
#PackagerProperty: IncludedModules = jdk.crypto.ec

as per Tips and special cases 7 in Integrated B4JPackager11 - The simple way to distribute standalone UI apps to specifically deal with javax.net.ssl.SSLHandshakeException errors, however of recent times the applications have intermittently been failing when making a subsequent https call and returning the following error:

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at java.base/sun.security.ssl.Alert.createSSLException(Unknown Source)
at java.base/sun.security.ssl.Alert.createSSLException(Unknown Source)
at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)
at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Unknown Source)
at java.base/sun.security.ssl.TransportContext.dispatch(Unknown Source)
at java.base/sun.security.ssl.SSLTransport.decode(Unknown Source)
at java.base/sun.security.ssl.SSLSocketImpl.decode(Unknown Source)
at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(Unknown Source)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at b4j/okhttp3.internal.connection.RealConnection.connectTls(Unknown Source)
at b4j/okhttp3.internal.connection.RealConnection.establishProtocol(Unknown Source)
at b4j/okhttp3.internal.connection.RealConnection.connect(Unknown Source)
at b4j/okhttp3.internal.connection.StreamAllocation.findConnection(Unknown Source)
at b4j/okhttp3.internal.connection.StreamAllocation.findHealthyConnection(Unknown Source)
at b4j/okhttp3.internal.connection.StreamAllocation.newStream(Unknown Source)
at b4j/okhttp3.internal.connection.ConnectInterceptor.intercept(Unknown Source)
at b4j/okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
at b4j/okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
at b4j/okhttp3.internal.cache.CacheInterceptor.intercept(Unknown Source)
at b4j/okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
at b4j/okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
at b4j/okhttp3.internal.http.BridgeInterceptor.intercept(Unknown Source)
at b4j/okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
at b4j/okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(Unknown Source)
at b4j/okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
at b4j/okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
at b4j/okhttp3.RealCall.getResponseWithInterceptorChain(Unknown Source)
at b4j/okhttp3.RealCall.execute(Unknown Source)
at b4j/anywheresoftware.b4h.okhttp.OkHttpClientWrapper.executeWithTimeout(Unknown Source)
at b4j/anywheresoftware.b4h.okhttp.OkHttpClientWrapper.access$0(Unknown Source)
at b4j/anywheresoftware.b4h.okhttp.OkHttpClientWrapper$ExecuteHelper.run(Unknown Source)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)

The only way to recover is to close and reopen the application and it then operates as expected.

Could this be solely due to the server now not liking subsequent calls sometimes, noting the application does not make repeated calls or are there any other suggestions?
 
Solution
it really is related to java jdk version.
with jdk 11 downloaded from here https://www.b4x.com/b4j.html give the error

but now i m using from this link

any error, works 100%.

thanks all.

Erel

B4X founder
Staff member
Licensed User
Longtime User
Hard to say. Might be a server problem, though it is strange that it only gets resolved after restarting the app.

Two things that you can try:
1. Try to send the request again after it fails. You should do it in a loop and sleep for a few seconds between the attempts.
2. Test it when you run it in release mode. See if it is related to the packaged app or not.
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
I'm having the same problem, after it happens once, all future requests get the same error, regardless of whether you wait a few seconds or minutes before making the next request.

The only way it works again is to close the app and start again.
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
@Douglas Farias while I don't like to see anyone encountering problems, I'm pleased someone else also has this error.

The strange thing is that prompted by your post I went back to the app to try point 2. suggested by @Erel and the packaged app is working perfectly on repeated calls. Perhaps it may have been related to the server, but I don't like problems which go away without doing anything.

In your case, perhaps try that point 2 suggestion and see if there is a difference between the app run in release mode from the IDE and the packaged app.
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
Hello how are you?
About changing the package and trying in release mode I'm already doing it, but the error continues.

Really I was doing a lot of requests per second, with a sleep of 800ms each request, this could probably be the reason for the error.

but the point here, the real problem is to understand why after an error, all other requests give error, and it only works again when closing the app and starting again, after the error happens once, you can wait the time whatever, it will happen again in the next request, but closing the app and opening it again doesn't happen. That's what I wanted to try to fix.

obs: i m closing all requests with j.Release

Thanks for the answer.
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
Yes I agree. It would be good to know how to "clear" the error, as appears to happen when the app is closed, so that the user does not have to close and reopen the app. I also use j.Release to close the request whether it is successful or not.
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
Just an FYI that may be related, recently some of my customers reported this error for some sites my app interacts with over https.

I had originally distributed my app with the Java 11 version that Erel had on the website - 11.0.1. Only the customers running 11.0.1 were having the issue.

For some reason this version is no longer trusting some certificate chains. I believe this is due to the root certificate chains included in the JDK.

Upgrading to a newer version of Java 11 solved the problem.
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
Thanks for the FYI @tchart.

If we use the integrated packager to create the app, how do we upgrade to a later version of Java than 11.0.1 given the B4J installation instructions say "Note that other versions of Java 11+, not downloaded from B4X, will not work as JavaFX will be missing."?
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
Thanks for the FYI @tchart.

If we use the integrated packager to create the app, how do we upgrade to a later version of Java than 11.0.1 given the B4J installation instructions say "Note that other versions of Java 11+, not downloaded from B4X, will not work as JavaFX will be missing."?
Im not sure. My app is a server app so there is no requirement for JFX for me. I have a different method to build an installer.
 
Upvote 0

Chris2

Active Member
Licensed User
I've not tried this myself (it's on my To Do list). Check @Erel's post #2.
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
it really is related to java jdk version.
with jdk 11 downloaded from here https://www.b4x.com/b4j.html give the error

but now i m using from this link

any error, works 100%.

thanks all.
 
Upvote 0
Solution

bdunkleysmith

Active Member
Licensed User
Longtime User
Upvote 0
Top