Skip to content

DefaultLockRepository fails silently w/ PostgreSQL #8623

Closed
@agebhar1

Description

@agebhar1

In what version(s) of Spring Integration are you seeing this issue?

unreleased main

Describe the bug

In #8606 ttl type moved to Duration and is used with JdbcTemplate, e.g.

public boolean acquire(String lock) {
Boolean result =
this.serializableTransactionTemplate.execute(
transactionStatus -> {
if (this.template.update(this.updateQuery, this.id, Instant.now(),
this.region, lock, this.id, Instant.now().minus(this.ttl)) > 0) {
return true;
}
try {
return this.template.update(this.insertQuery, this.region, lock, this.id,
Instant.now()) > 0;
}
catch (DataIntegrityViolationException ex) {
return false;
}
});
return Boolean.TRUE.equals(result);
}

Acquire fails silently with PostgreSQL and propagated back to:

public void lock() {
this.delegate.lock();
while (true) {
try {
while (!doLock()) {
Thread.sleep(this.idleBetweenTries.toMillis());
}
break;
}
catch (TransientDataAccessException | TransactionTimedOutException | TransactionSystemException e) {
// try again
}
catch (InterruptedException e) {
/*
* This method must be uninterruptible so catch and ignore
* interrupts and only break out of the while loop when
* we get the lock.
*/
}
catch (Exception e) {
this.delegate.unlock();
rethrowAsLockException(e);
}
}
}

and handled in the last clause:

catch (Exception e) {
  this.delegate.unlock();
  rethrowAsLockException(e);
}

with this exception:

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [UPDATE LOCK
SET CLIENT_ID=?, CREATED_DATE=?
WHERE REGION=? AND LOCK_KEY=? AND (CLIENT_ID=? OR CREATED_DATE<?)
]; nested exception is org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.time.Instant. Use setObject() with an explicit Types value to specify the type to use.

Expected behavior

Should acquire the lock with PostgreSQL.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions