Skip to content

Commit 901ec95

Browse files
Retry randomUUID() to mitigate intermittent java NativeSeedGenerator failure (#1705)
* Retry once * Added logging * Changed logging level
1 parent 50b1251 commit 901ec95

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3178,7 +3178,17 @@ private InetSocketAddress connectHelper(ServerPortPlaceHolder serverInfo, int ti
31783178

31793179
setState(State.Connected);
31803180

3181-
clientConnectionId = UUID.randomUUID();
3181+
try {
3182+
clientConnectionId = UUID.randomUUID();
3183+
} catch (InternalError e) {
3184+
// Java's NativeSeedGenerator can sometimes fail on getSeedBytes(). Exact reason is unknown but high system
3185+
// load seems to contribute to likelihood. Retry once to mitigate.
3186+
if (connectionlogger.isLoggable(Level.FINER)) {
3187+
connectionlogger.finer(toString() + " Generating a random UUID has failed due to : " + e.getMessage() + "Retrying once.");
3188+
}
3189+
clientConnectionId = UUID.randomUUID();
3190+
}
3191+
31823192
assert null != clientConnectionId;
31833193

31843194
Prelogin(serverInfo.getServerName(), serverInfo.getPortNumber());

0 commit comments

Comments
 (0)