Skip to content

Commit

Permalink
locker: With potential connection leak when acquiring lock
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrossie committed Feb 3, 2025
1 parent a08f1d2 commit d22bc21
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ public boolean isFree(final String service, final String lockKey) {
@Override
protected GlobalLock doLock(final String lockName) {
Connection connection = null;
boolean obtained = false;
try {
connection = dataSource.getConnection();
obtained = globalLockDao.lock(connection, lockName, timeout, timeUnit);
final boolean obtained = globalLockDao.lock(connection, lockName, timeout, timeUnit);
if (obtained) {
final GlobalLock lock = getGlobalLock(connection, lockName, new ResetReentrantLockCallback() {
@Override
Expand All @@ -84,7 +83,7 @@ public boolean reset(final String lockName) {
} catch (final SQLException e) {
logger.warn("Unable to obtain lock for {}", lockName, e);
} finally {
if (!obtained && connection != null) {
if (connection != null) {
try {
connection.close();
} catch (final SQLException e) {
Expand Down

0 comments on commit d22bc21

Please sign in to comment.