From 901ec95427f8e8333296346c93a69efbd012b366 Mon Sep 17 00:00:00 2001 From: Wei Zhang <53021889+v-zhangw@users.noreply.github.com> Date: Wed, 8 Dec 2021 15:41:50 -0800 Subject: [PATCH] Retry randomUUID() to mitigate intermittent java NativeSeedGenerator failure (#1705) * Retry once * Added logging * Changed logging level --- .../sqlserver/jdbc/SQLServerConnection.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index c792ddc9a..c9e36b280 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -3178,7 +3178,17 @@ private InetSocketAddress connectHelper(ServerPortPlaceHolder serverInfo, int ti setState(State.Connected); - clientConnectionId = UUID.randomUUID(); + try { + clientConnectionId = UUID.randomUUID(); + } catch (InternalError e) { + // Java's NativeSeedGenerator can sometimes fail on getSeedBytes(). Exact reason is unknown but high system + // load seems to contribute to likelihood. Retry once to mitigate. + if (connectionlogger.isLoggable(Level.FINER)) { + connectionlogger.finer(toString() + " Generating a random UUID has failed due to : " + e.getMessage() + "Retrying once."); + } + clientConnectionId = UUID.randomUUID(); + } + assert null != clientConnectionId; Prelogin(serverInfo.getServerName(), serverInfo.getPortNumber());