Skip to content

Commit 694bef3

Browse files
committed
Avoid metadata access in driver connect advice for Oracle sharded connections
Accessing sharded metadata at this point could loop back into the pool, leading to starvation.
1 parent 00856e0 commit 694bef3

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/DriverInstrumentation.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,26 @@ public static void addDBInfo(
7373
}
7474
String connectionUrl = url;
7575
Properties connectionProps = props;
76-
try {
77-
DatabaseMetaData metaData = connection.getMetaData();
78-
connectionUrl = metaData.getURL();
79-
if (null != connectionUrl && !connectionUrl.equals(url)) {
80-
// connection url was updated, check to see if user has also changed
81-
String connectionUser = metaData.getUserName();
82-
if (null != connectionUser
83-
&& (null == props || !connectionUser.equalsIgnoreCase(props.getProperty("user")))) {
84-
// merge updated user with original properties
85-
connectionProps = new Properties(props);
86-
connectionProps.put("user", connectionUser);
76+
if (null == props
77+
|| !Boolean.parseBoolean(props.getProperty("oracle.jdbc.useShardingDriverConnection"))) {
78+
try {
79+
DatabaseMetaData metaData = connection.getMetaData();
80+
connectionUrl = metaData.getURL();
81+
if (null != connectionUrl && !connectionUrl.equals(url)) {
82+
// connection url was updated, check to see if user has also changed
83+
String connectionUser = metaData.getUserName();
84+
if (null != connectionUser
85+
&& (null == props || !connectionUser.equalsIgnoreCase(props.getProperty("user")))) {
86+
// merge updated user with original properties
87+
connectionProps = new Properties(props);
88+
connectionProps.put("user", connectionUser);
89+
}
90+
} else {
91+
connectionUrl = url; // fallback in case updated url is null
8792
}
88-
} else {
89-
connectionUrl = url; // fallback in case updated url is null
93+
} catch (Throwable ignored) {
94+
// use original values
9095
}
91-
} catch (Throwable ignored) {
92-
// use original values
9396
}
9497
Connection connWithContext = connection;
9598
if (connectionUrl.startsWith("**internally_generated**", connectionUrl.indexOf("://") + 3)) {

0 commit comments

Comments
 (0)