Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lock around jdbc connection #11877

Merged
merged 9 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .in-toto/tag.0244aaa8.link
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"signatures":[{"keyid":"0244aaa8dd1efe4730a4f1ca392c882e0da0c6c8","other_headers":"04000108001d1621040244aaa8dd1efe4730a4f1ca392c882e0da0c6c805026230abe8","signature":"477df767820262cce7c7d59cdc4484e0500c1cc3e0e5e49f71c6ff52ece0abcf812c6e3519c45b4f3aaacfdf29d286dfd8fede3df74925cd5e937262df4ee2302e2a25af782eec9cf97f87780866cc766d1fb0ca66d7cb384b756ab48e7c84dea8db4e45d1d9baa00df15ceb2df0cc695e06a6cd7e37b1e3ee20bbb0790f058e4e2548c4591e8e8aea4ce9d68d0baa6d58323391361080f5c9802c4350666fa96203b3933a6f9ea55d32565219d13355994bf1113cdb83e93306d958c8862a541c737760be98cd4dccfd4cab4616d277c2b7c88b5fb0dc0ce9c7431565a16fc5d6bdd1ff576f40db48c666d862a8d49ae6e768d72acb073f92c49bb47ac78aa9aecb019c77da5fb8548e36c124a3525f67bbcf886893267df3c35ce8024c004167953cc60cf48bb11ce4c232150391e03452b8d628af28aa82ff1d4ee54a092ea4df6e1be1c796e7ccf387c2ee655b062a1006add981bea6d542f8257ffac90cafb56e8b0577a204cd5f93aa980b674a2a0c00f08b4bc45116d8b86207cbda6a4f57bf47f96961b779801df6d6dbc903d8dbc3d2120a6e303f506809db5a1a1cbfc64606671b18436d81a25ef13692000006681200aa7f7c19b1a00499145d5200ead9f673f13c66d9a10b60239f375e1e7bf4d85e12449d7b0dfde96d6a7384a33ce80ff50fff84dcc60c727693bd30ae5bbfba68638f5f67e37a7589f6a469"}],"signed":{"_type":"link","byproducts":{},"command":[],"environment":{},"materials":{},"name":"tag","products":{"foundationdb/datadog_checks/__init__.py":{"sha256":"88e10cc2794e4567b374ef3edafc4120f491dfb0fb2468e5b99f1fe79bf3c65b"},"foundationdb/datadog_checks/foundationdb/__about__.py":{"sha256":"b33b0fc332d7b4c6cf12762fbde66b89ada47105a132ff1d08746ca6331b0e60"},"foundationdb/datadog_checks/foundationdb/__init__.py":{"sha256":"ddba65c47222adb9d8ec327612c63f77a8d4d0ad91d529cdc6c454b3b162fe98"},"foundationdb/datadog_checks/foundationdb/check.py":{"sha256":"9536d61e8ae67ce59bbb072f9c2fe028e5d7dcd5d3bb5634b0811dba204d9003"},"foundationdb/datadog_checks/foundationdb/config_models/__init__.py":{"sha256":"c9cf5c66894430e7edbb00d00613b58ccfd38360f2fe490a23c17cf71ed294dc"},"foundationdb/datadog_checks/foundationdb/config_models/defaults.py":{"sha256":"fe51d50901a37ceb0e163e263d0402a8c4045b163e1580eae1132d6b4dfed0a1"},"foundationdb/datadog_checks/foundationdb/config_models/instance.py":{"sha256":"b74db03dc05e1e1830afdf4131410d2adb75b976d7dd9eef65093f50f2033418"},"foundationdb/datadog_checks/foundationdb/config_models/shared.py":{"sha256":"65c3225007c0d4b7bbfb636a4ff3b4e77f3e0a218d1211d4cb14c051522bea49"},"foundationdb/datadog_checks/foundationdb/config_models/validators.py":{"sha256":"0424fe17778b76e1b589b9564d0d543d1b71dba1edd6e5d71a7c528dddf68e0b"},"foundationdb/datadog_checks/foundationdb/data/conf.yaml.example":{"sha256":"bb4aed296803aa1ef3ca02cf7c0df7089c1dfae8876fe452f55e26ba049602f5"},"foundationdb/pyproject.toml":{"sha256":"c3dab442f87aa4a61d5bc21a62479e0df86811985337cdec07520f21f0f023f6"},"foundationdb/setup.py":{"sha256":"04d7e924af6938ce7c60727810e21fbc2aaad2440188f392bdda268a6cf6cbb7"}}}}
{"signatures":[{"keyid":"0244aaa8dd1efe4730a4f1ca392c882e0da0c6c8","other_headers":"04000108001d1621040244aaa8dd1efe4730a4f1ca392c882e0da0c6c805026261833b","signature":"6a6cfc84aca651a2aa6c69facdbeb1e4ddb4c571efc264c4cabdf7c1e9ecbaef861b763e8c404d43cf7f5e3f0da58e4d8d464799c0b37527e7c8783299f3737a5211367bb0e2ce669e901f29818885c9d759fe77be60e035d975eacede8cdfc847507330ded27804edb5d9e9215a41c06525d5ffa354880b7dc628861de8bae396ecf9c5ee4a26bc68d6e8584d3fb54d745f0e0d757025482b0ec3483a94f4722611cd4e4e0c0e799299c1d199d50f85c5a37f474497c9e41a0bcc2b4659cae4bf85bcf1a33d5e164e05d44a774b47adc368ed48e4b8c340b1d635b3c78ce560ad5777d40db15eb8c6ad2ca9087b9fa19ce19e9856afbcf4d39a9dbe034e006d87dd73dede1605bd2c0d9d6a08e0764bf0ed6a64944fe3b6d5f81fe6a29f919fbcab4b9c6c6779814589ca5471c67442beb2203461c46684cb8d50990787029c458ba88723cfc7dc8bc274e4119704481666dabc6119ab060cb17d428ad1bbeb870d1f4a15d2714f5510ce814f8c9ef5cfdc4027a19ff23290c2bc88e20162d7ea758856fe7601bca4e60a787c851b3f5839abe5a49480f134f45fea74b0e6f91ca998e0618e59eb0c9bfc79bb32c10c70ad02a4a317429d2555467a24ca6708f2a7dbe72b02fe0c436095277adda4db080327c331e872cc577a041cc1d3843ac142be7c48658acf2dc6a7bafe0025257a94131f5584446a27a9ecda95db5656"}],"signed":{"_type":"link","byproducts":{},"command":[],"environment":{},"materials":{},"name":"tag","products":{"oracle/datadog_checks/__init__.py":{"sha256":"fe73dc8f45d35205d366455edc6e8c3a8b29870d773b6f103d5261e25f757b25"},"oracle/datadog_checks/oracle/__about__.py":{"sha256":"72738f1f96354dbfda9015ccea758e49849dee3e840f302535d7bc3063611f14"},"oracle/datadog_checks/oracle/__init__.py":{"sha256":"909c6bc83f6a43441d67504486f17ee7621e6bbc6b447460f0c3c3f75311565b"},"oracle/datadog_checks/oracle/config_models/__init__.py":{"sha256":"c9cf5c66894430e7edbb00d00613b58ccfd38360f2fe490a23c17cf71ed294dc"},"oracle/datadog_checks/oracle/config_models/defaults.py":{"sha256":"9d175cc1790e61694d7a79bdb02514555716bc5c2d49d0b64f901b21efc91b7a"},"oracle/datadog_checks/oracle/config_models/instance.py":{"sha256":"f97a5dce1b8a6d64517c63300127d3b15cd42561fccc18a2cb1a1292de15d951"},"oracle/datadog_checks/oracle/config_models/shared.py":{"sha256":"50e1bd92923890c0bf0689416fdb1f5192e49202c10f6798ab5e0e613fe6ede8"},"oracle/datadog_checks/oracle/config_models/validators.py":{"sha256":"e316c76c34f13789d5c887cbb3037ff09e999e123193634002513572a1df00db"},"oracle/datadog_checks/oracle/data/conf.yaml.example":{"sha256":"23aa06364ac8a3f7944811becccfbdcc64cb5196d6571056a0effd5d8ceefd27"},"oracle/datadog_checks/oracle/oracle.py":{"sha256":"4cc05b476081ed6297847db092b23a526f1502c6c602745767586e5e56f9e24c"},"oracle/datadog_checks/oracle/queries.py":{"sha256":"85ed6edc26c4198983efd0ca8a6e1ad910e0b504dad4388350e807db6647f86e"},"oracle/pyproject.toml":{"sha256":"d1971da0f49d2c7a52c9121337b16dfee9d0de68a3e46c19dd6a11bb4871ddb6"},"oracle/setup.py":{"sha256":"a8a1345b68715a7e6d0584ad5428715ba8a7dc31ee4775b803d4023b948e14bc"}}}}
4 changes: 4 additions & 0 deletions oracle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG - oracle

## 3.9.4-beta / 2022-04-21

* [Fixed] Do not close closed connection. See [#11874](https://github.com/DataDog/integrations-core/pull/11874).

## 3.9.3 / 2022-04-14

* [Fixed] Handle NoneType protocol validation. See [#11837](https://github.com/DataDog/integrations-core/pull/11837).
Expand Down
2 changes: 1 addition & 1 deletion oracle/datadog_checks/oracle/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)

__version__ = "3.9.3"
__version__ = "3.9.4-beta"
22 changes: 14 additions & 8 deletions oracle/datadog_checks/oracle/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import itertools
import threading
from contextlib import closing

import cx_Oracle
Expand Down Expand Up @@ -80,6 +81,11 @@ def __init__(self, name, init_config, instances):

self._query_errors = 0
self._connection_errors = 0
# When using JDBC connection and multiple instances of the check
# It causes the following error
# Native Library .../_jpype.cpython-38-x86_64-linux-gnu.so already loaded in another classloader
# To prevent it we're adding a lock over jpype operations
self.jdbc_lock = threading.Lock()

def _fix_custom_queries(self):
"""
Expand Down Expand Up @@ -230,15 +236,15 @@ def _jdbc_connect(self):

self.log.debug("Connecting via JDBC with connection string: %s", connect_string)
try:
if jpype.isJVMStarted() and not jpype.isThreadAttachedToJVM():
jpype.attachThreadToJVM()
jpype.java.lang.Thread.currentThread().setContextClassLoader(
jpype.java.lang.ClassLoader.getSystemClassLoader()
with self.jdbc_lock:
if jpype.isJVMStarted() and not jpype.isThreadAttachedToJVM():
jpype.attachThreadToJVM()
jpype.java.lang.Thread.currentThread().setContextClassLoader(
jpype.java.lang.ClassLoader.getSystemClassLoader()
)
connection = jdb.connect(
self.ORACLE_DRIVER_CLASS, connect_string, jdbc_connect_properties, self._jdbc_driver
)

connection = jdb.connect(
self.ORACLE_DRIVER_CLASS, connect_string, jdbc_connect_properties, self._jdbc_driver
)
self.log.debug("Connected to Oracle DB using JDBC connector")
return connection
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion requirements-agent-release.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ datadog-openldap==1.10.0
datadog-openmetrics==2.1.0
datadog-openstack-controller==2.1.0
datadog-openstack==1.13.0
datadog-oracle==3.9.3
datadog-oracle==3.9.4-beta
datadog-pan-firewall==1.1.0
datadog-pdh-check==1.16.0; sys_platform == 'win32'
datadog-pgbouncer==4.2.0; sys_platform != 'win32'
Expand Down