Skip to content

Commit

Permalink
Fix JDBC instrumentation deadlock (#4191)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored and github-actions committed Sep 29, 2021
1 parent 15cfcfa commit 3539019
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ public static Connection connectionFromStatement(Statement statement) {
}

public static DbInfo extractDbInfo(Connection connection) {
return JdbcData.connectionInfo.computeIfAbsent(connection, JdbcUtils::computeDbInfo);
// intentionally not using computeIfAbsent() since that would perform computeDbInfo() under a
// lock, and computeDbInfo() calls back to the application code via Connection.getMetaData()
// which could then result in a deadlock
// (e.g. https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/4188)
DbInfo dbInfo = JdbcData.connectionInfo.get(connection);
if (dbInfo == null) {
dbInfo = computeDbInfo(connection);
JdbcData.connectionInfo.put(connection, dbInfo);
}
return dbInfo;
}

public static DbInfo computeDbInfo(Connection connection) {
Expand Down

0 comments on commit 3539019

Please sign in to comment.