Skip to Main Content
  • Questions
  • Row lock doesn't released after connection closed from client side due to network level failure

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Manjula.

Asked: September 08, 2016 - 11:43 am UTC

Last updated: September 09, 2016 - 1:40 am UTC

Version: 12G

Viewed 1000+ times

You Asked

Hi Tom,

I have a problem related to row lock handling when there are can be network level failure between client and Oracle db server. I want to make sure that there won't be any stale locks at the server side. Let me explain my issue with an example scenario.

I have used the following code to get a row lock(using for update) and before calling resultSet.updateRow(); statement I tried to block the communication between client and server(using a firewall rule to block port 1521)

String forUpdateQuery = "SELECT NAME, AGE FROM MY_TEST WHERE AGE = ? FOR UPDATE";
Connection con = null;
try {
System.setProperty("oracle.jdbc.ReadTimeout", "30000");
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("URL", "UserName", "Password");

forUpdatePS = con.prepareStatement(forUpdateQuery, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
forUpdatePS.setInt(1, 25); //Setting age value to the prepared statement
ResultSet rs = forUpdatePS.executeQuery();
while (rs.next()) {
if (rs.getString("NAME") != null) {
rs.updateString("NAME", "New Name");
}
try {
Thread.sleep(10000);
//Within this 10 seconds I'm blocking the port 1521 thorugh the firewall
} catch (InterruptedException e) {
e.printStackTrace();
}
rs.updateRow();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
//cleanup
}

Following is DDL of the test table

CREATE TABLE APS_EMW.MY_TEST (
ID INT PRIMARY KEY NOT NULL ,
NAME VARCHAR(255) NULL ,
ADDRESS VARCHAR(255) NULL ,
AGE INTEGER NULL
);

As I beleive there should be a proper way to deal with these type of network level failures agaist row locks. I have tried reducing CONNET_TIME and IDLE_TIME to some finite values to check whether after that value my locks will disapear, but unfortunately neither of them works for me. Can you please help me to handle this type of connection failures when there are already acquired row locks? If there is a way to configure some timeout value to remove stale locks from the database server side which will be the best option for me, unfortunately I couldn't find a way to do this

Thanks,
Manjula

and Connor said...

Check out this AskTOm question

https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:453256655431

An IDLE_TIME should work, but there will be a latency until pmon comes along and cleans up the session

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

It's very helpful

Manjula Piyumal, September 08, 2016 - 4:30 pm UTC

Hi Tom,

Thanks a lot for your response and that helps a lot. I was able to solve my issue using IDLE_TIME together with resource_limit=true configurations. However, I want to check with you whether is it possible to set this resource_limit parameter per profile? The problem is, in the database that we are working on this issue runs multiple projects and we only have access to one project. My plan is to create a separate profile for my project and apply these two configurations on that profile. I know that IDLE_TIME can be set at the profile level, but not sure about the resource_limit parameter. Can you please help me to understand whether this is possible and my understanding on this is correct.

Thanks,
Manjula
Chris Saxon
September 09, 2016 - 1:40 am UTC

resource_limit is a database wide setting.

But you can have profiles per user, so those people with the default profile will not have the same limits that you apply in your custom profile.

IDLE_TIME works for me

Manjula Piyumal, September 12, 2016 - 4:11 am UTC

Thanks a lot Tom, IDLE_TIME configuration works for me