Based on my understanding of the issue from your description, and that you mentioned it is reproduced only on App Service ( locally it takes 200ms).
The issue you are experiencing may be due to the fact that the SSLContext is being initialized with null parameters. According to the Java docs, the SSLContext.init() method initializes this context. If the key manager, trust manager, or secure random parameters are null, then the installed security providers will be searched for the highest-priority implementation of the appropriate factory. This search is done in the order returned by Security.getProviders(). This may be causing the delay you are experiencing.
To isolate the issue/As for a workaround, you may try manually loading the key store. You can load certificates manually to the key store. Create an app setting, SKIP_JAVA_KEYSTORE_LOAD
, with a value of 1
to disable App Service from loading the certificates into the key store automatically.
All public certificates uploaded to App Service via the Azure portal are stored under /var/ssl/certs/. Private certificates are stored under /var/ssl/private/. You may interact or debug the Java Key Tool by opening an SSH connection to your App Service and running the command keytool.
Reference: Doc section Configure a Java app for Azure App Service | Manually load the key store
Kindly let us know how it goes, I'll follow-up with you further.