The Session That Holds a Lock and Does Nothing: Finding and Preventing Idle Blockers Behind Azure Load Balancers
Some outages are caused by a session that is not doing anything at all. An application server starts a transaction, updates a few rows, and then disappears: its container is replaced during a deployment, the node is drained, or a network device drops the connection. The database never hears about it. The session stays INACTIVE with its transaction open and its row locks held, and every other session that needs those rows waits behind it, until a DBA finds and kills it.
In Azure this happens more often than on premises, because load balancers and NAT gateways drop idle TCP flows silently after a few minutes, and Kubernetes replaces pods freely. This post finds such a blocker on Exadata Database Service in Oracle Database@Azure, ends it safely, and then configures the database so the problem resolves itself.
The Use Case
The order service runs in Azure Kubernetes Service and connects to a two-node RAC database on Exadata Database Service in Oracle Database@Azure. Twice in the last month, order entry froze for twenty minutes after a deployment. Both times, the cause was a session from a pod that no longer existed, holding locks on the same few rows of a stock table. Nobody noticed the blocker until users complained.
Environment used in this runbook
Database: Oracle Database 19c (19.24), PDB SALESPDB, two-node RAC on Exadata Database Service in Oracle Database@Azure
Clients: order-service pods in Azure Kubernetes Service, connection pools of 20 per pod
Network path: AKS virtual network peered with the database subnet, outbound flows through an Azure NAT gateway for some components
Azure idle timeout: 4 minutes by default on Azure Load Balancer rules, configurable up to 100 minutes
Licence: everything used here is part of Oracle Database Enterprise Edition
Why Idle Blockers Happen
The client disappears without closing. A killed pod or a dropped network flow leaves no FIN or RST for the database to see, so the server process keeps waiting for the next call.
The session keeps its transaction. Locks are released only by COMMIT, ROLLBACK or the end of the session, and an orphaned session does none of these.
Idle flows are dropped silently. Azure Load Balancer drops idle flows after its timeout without telling either end, unless TCP reset is enabled on the rule.
The database can check. Dead connection detection probes idle connections, and MAX_IDLE_BLOCKER_TIME ends sessions that sit idle while blocking others.
Step 1: Find the Blocked Sessions and Their Final Blocker
Start with the sessions that are waiting, across all instances. FINAL_BLOCKING_SESSION points to the session at the head of the chain, which is the one to look at.
SQL |
-- Connected to SALESPDB as a DBA COLUMN event FORMAT A30
SELECT inst_id, sid, event, seconds_in_wait AS wait_s, final_blocking_instance AS blk_inst, final_blocking_session AS blk_sid FROM gv$session WHERE blocking_session IS NOT NULL ORDER BY seconds_in_wait DESC FETCH FIRST 5 ROWS ONLY; |
Expected output |
INST_ID SID EVENT WAIT_S BLK_INST BLK_SID
---------- ---------- ------------------------------ ---------- ---------- ----------
1 1487 enq: TX - row lock contention 912 2 733
2 2106 enq: TX - row lock contention 884 2 733
1 412 enq: TX - row lock contention 861 2 733
2 958 enq: TX - row lock contention 847 2 733
1 2391 enq: TX - row lock contention 803 2 733What to expect: Several sessions on both instances waiting on row locks for about 15 minutes, all with the same final blocker: session 733 on instance 2. On RAC, always read FINAL_BLOCKING_INSTANCE together with the session, because the same SID can exist on both instances.
Step 2: Look at the Blocker
Look at the blocking session before doing anything to it. How long has it been idle, where did it come from, and what did it run last?
SQL |
COLUMN username FORMAT A10 COLUMN machine FORMAT A26 COLUMN status FORMAT A8
SELECT s.sid, s.serial#, s.username, s.status, s.machine, s.last_call_et AS idle_s, s.prev_sql_id, TO_CHAR(t.start_date, 'YYYY-MM-DD HH24:MI') AS txn_start FROM gv$session s LEFT JOIN gv$transaction t ON t.inst_id = s.inst_id AND t.ses_addr = s.saddr WHERE s.inst_id = 2 AND s.sid = 733; |
Expected output |
SID SERIAL# USERNAME STATUS MACHINE IDLE_S PREV_SQL_ID TXN_START
---------- ---------- ---------- -------- -------------------------- ---------- ------------- ----------------
733 41822 ORDER_SVC INACTIVE order-service-7d9f2-xk4lp 921 3sk1qm8w2c7vd 2026-11-28 10:44What to expect: An INACTIVE session from the pod order-service-7d9f2-xk4lp, idle for 921 seconds with a transaction open since 10:44. Ask the application team to check whether that pod still exists; in this case it was replaced by the deployment at 10:45, so the session is an orphan. PREV_SQL_ID shows the last statement, here the update of the stock table.
Step 3: End the Blocking Session
Kill the orphaned session on its own instance. The database rolls back its open transaction and releases the locks, and the waiting sessions continue.
SQL |
ALTER SYSTEM KILL SESSION '733,41822,@2' IMMEDIATE;
SELECT COUNT(*) AS still_blocked FROM gv$session WHERE blocking_session IS NOT NULL; |
Expected output |
System altered.
STILL_BLOCKED
-------------
0What this does: The @2 tells the database to kill the session on instance 2, so the command can be run from any instance. IMMEDIATE ends the session without waiting for it to finish its current call. The rollback of a small transaction takes seconds; for a large one, the locks are held until the rollback completes, which V$TRANSACTION shows as USED_UREC going down.
Tip: Never kill a blocker before checking that it is really idle and orphaned. An ACTIVE session with a long LAST_CALL_ET is doing work, and killing it can mean a long rollback that holds the same locks even longer.
Step 4: Check the Connection Path for Silent Drops
Before changing the database, confirm what the network does with idle connections. Ask the network team for the idle timeout of every load balancer rule and NAT gateway between the pods and the database, or read it with the Azure CLI.
Shell |
# Idle timeout of the load balancer rules in front of the database clients az network lb rule list --resource-group rg-sales-prod --lb-name lb-sales-db \ --query "[].{rule:name, idleTimeout:idleTimeoutInMinutes, tcpReset:enableTcpReset}" -o table
# Idle timeout of the NAT gateway used by the AKS node pool az network nat gateway show --resource-group rg-sales-aks --name nat-aks-egress \ --query "{name:name, idleTimeout:idleTimeoutInMinutes}" -o table |
Expected output |
Rule IdleTimeout TcpReset
------------ ------------- ----------
oracle-1521 4 False
Name IdleTimeout
-------------- -------------
nat-aks-egress 4What to expect: Both devices drop idle flows after 4 minutes, and the load balancer does so silently, without sending a reset. A connection that stays idle for longer than 4 minutes is gone from the network's point of view, but both the database and the client still believe it exists. Any keepalive from the database must therefore come more often than every 4 minutes.
Step 5: Turn On Dead Connection Detection
Set SQLNET.EXPIRE_TIME in the server-side sqlnet.ora of the database home on every database server. With a value of 1, the database probes each idle connection every minute, well inside the 4-minute timeout.
Shell |
# On each database server of the VM cluster, as the oracle user grep -i expire_time $ORACLE_HOME/network/admin/sqlnet.ora || \ echo "SQLNET.EXPIRE_TIME = 1" >> $ORACLE_HOME/network/admin/sqlnet.ora
grep -i expire_time $ORACLE_HOME/network/admin/sqlnet.ora |
Expected output |
SQLNET.EXPIRE_TIME = 1What this does: New connections created after the change are probed every minute while idle. The probes keep the flow alive in the load balancer and NAT tables, so healthy idle connections are no longer dropped. If a client has really gone, the probe fails, the database notices within a few minutes, ends the session and rolls back its transaction. Existing connections are not affected, so the change takes full effect after the next restart of the connection pools.
Step 6: Limit How Long an Idle Session May Block
Dead connection detection handles clients that are gone. It does not help when the client is alive but forgets its transaction, for example after an exception that skipped the rollback. For that case, set MAX_IDLE_BLOCKER_TIME, available since Oracle Database 19c, which ends a session that has been idle for the given number of minutes while it blocks others.
SQL |
ALTER SYSTEM SET max_idle_blocker_time = 5 SCOPE = BOTH SID = '*';
COLUMN name FORMAT A24 COLUMN value FORMAT A6
SELECT inst_id, name, value FROM gv$parameter WHERE name IN ('max_idle_blocker_time', 'max_idle_time') ORDER BY inst_id, name; |
Expected output |
System altered.
INST_ID NAME VALUE
---------- ------------------------ ------
1 max_idle_blocker_time 5
1 max_idle_time 0
2 max_idle_blocker_time 5
2 max_idle_time 0What this does: A session that has been idle for 5 minutes while holding a resource another session waits for is ended by the database, and its transaction is rolled back. Sessions that are idle but block nobody are left alone, which is why this parameter suits connection pools better than MAX_IDLE_TIME, which ends any idle session and would break pooled connections that are simply waiting for work.
Step 7: Find Idle Sessions with Open Transactions
Add a check that finds the risk before it becomes an outage: sessions that are idle but hold an open transaction, whether or not anyone is blocked yet.
SQL |
COLUMN machine FORMAT A26
SELECT s.inst_id, s.sid, s.machine, s.last_call_et AS idle_s, t.used_urec AS undo_records FROM gv$session s JOIN gv$transaction t ON t.inst_id = s.inst_id AND t.ses_addr = s.saddr WHERE s.status = 'INACTIVE' AND s.last_call_et > 120 ORDER BY s.last_call_et DESC; |
Expected output |
INST_ID SID MACHINE IDLE_S UNDO_RECORDS
---------- ---------- -------------------------- ---------- ------------
1 1844 report-worker-5c8b1-qz7tm 164 3What to expect: One session from a report worker, idle for almost three minutes with a small open transaction. It blocks nobody yet, so MAX_IDLE_BLOCKER_TIME does not act. Report such sessions to the application team: an idle session with an open transaction is almost always a missing COMMIT or ROLLBACK in the code.
Step 8: Make the Pods Close Connections Properly
Part of the fix belongs in the application platform. When Kubernetes stops a pod, the application should get time to finish or roll back its transactions and close its connections before the container is killed.
Shell |
# Check the grace period and the preStop hook of the deployment kubectl -n orders get deployment order-service \ -o jsonpath='{.spec.template.spec.terminationGracePeriodSeconds}{"\n"}{.spec.template.spec.containers[0].lifecycle.preStop.exec.command}{"\n"}' |
Expected output |
30
["sh","-c","sleep 10"]What to expect: A grace period of 30 seconds and a preStop hook that waits 10 seconds, so the pod is removed from the service before it stops. Ask the developers to close the connection pool on SIGTERM, rolling back open work; with that in place, a rolling deployment no longer leaves orphaned sessions behind.
Step 9: Verify After the Next Deployment
During the next deployment of the order service, watch for blocked sessions and orphaned transactions while the pods are replaced.
SQL |
SELECT inst_id, SUM(CASE WHEN blocking_session IS NOT NULL THEN 1 ELSE 0 END) AS blocked, SUM(CASE WHEN status = 'INACTIVE' AND last_call_et > 300 THEN 1 ELSE 0 END) AS idle_5min FROM gv$session WHERE username = 'ORDER_SVC' GROUP BY inst_id ORDER BY inst_id; |
Expected output |
INST_ID BLOCKED IDLE_5MIN
---------- ---------- ----------
1 0 34
2 0 31What to expect: No blocked sessions during the rollout. The idle sessions are pooled connections waiting for work, which is normal; they hold no transaction and block nobody, and with dead connection detection they are probed every minute, so the network keeps them alive and the database ends them if their pod is gone.
Summary
An idle session that holds locks can stop an application as surely as a crash. When it happens, find the final blocker across RAC instances in GV$SESSION, check that it is idle and orphaned, and kill it with ALTER SYSTEM KILL SESSION on its own instance. Then remove the cause: check the idle timeouts of the Azure load balancers and NAT gateways, set SQLNET.EXPIRE_TIME to a value below them in the server-side sqlnet.ora, and set MAX_IDLE_BLOCKER_TIME so the database ends idle blockers on its own. Watch for idle sessions with open transactions, and make the pods close their connections properly when Kubernetes stops them.
Comments