AFCF: VSAM file deadlock with another task
An AFCF abend means CICS found that a file control request would deadlock the task with another transaction, so it abended the task instead of letting both wait forever. It applies to VSAM files accessed in non-RLS mode.
Other names for this code
Also written as AFCF abend, CICS AFCF, abend AFCF, AFCF deadlock, VSAM deadlock CICS.
What it means
When a task updates a recoverable file, CICS locks each record it changes and keeps the lock until the unit of work ends at the next syncpoint. Another task that wants one of those records has to wait. Now suppose task A holds record 1 and asks for record 2, while task B holds record 2 and asks for record 1. Neither can ever go on.
For VSAM files in non-RLS mode, CICS file control looks for this. When a request would complete a circle of waits like that, CICS abends the task that is about to enter it with AFCF. Its updates are backed out, which releases its locks, and the other task gets its record and carries on. If a task would deadlock with itself, for example by making conflicting requests against the same control interval, the code is AFCG instead.
Files opened in RLS mode work differently. VSAM RLS manages their record locks, and a long wait for one of those ends in AFCV. File control also only sees its own locks. A deadlock between a record lock and some other kind of resource, such as an ENQ, isn't caught this way. Those tasks wait until a deadlock timeout (DTIMOUT) ends one of them with AKCS, or for good if the transactions have no DTIMOUT.
Common causes
- Two transactions update the same records in a different order. This is IBM's first example and the most common case.
- Two transactions update records in two recoverable files, one doing file A then file B and the other doing file B then file A.
- Long units of work that hold many record locks, such as a loop that reads and updates many records without a syncpoint.
- A conversational transaction that holds record locks while it waits for the user to press Enter, which stretches the time other tasks can collide with it.
- A batch-style task running in the region that updates the same records as online transactions.
How to find the problem
- Find the DFHAC message for the abend in the region's message log. It names the transaction and the time.
- In the transaction dump, EIBDS shows the last file the task used, and the trace shows the request that was refused.
- List the other transactions that update the same file or files, and compare the order in which they read for update, write and delete records.
- If the problem only appears under load, check which transactions run at the same time as the failing one. The clash needs two tasks working on overlapping records at once.
How to fix it
- Make every program update records in the same order, for example in ascending key order, and touch files in a fixed order.
- Keep units of work short. In long update loops, take a syncpoint every so many records so locks are released sooner.
- Use pseudo-conversational design so no task holds record locks while waiting for terminal input.
- Let the abended transaction be run again. Its updates were backed out, so rerunning it doesn't apply anything twice.
IBM documentation
IBM documentation: AFCF. Use the documentation for your installed release.
Related codes
Questions
What is the difference between AFCF and AFCG?
AFCF means the task would deadlock with another transaction. AFCG means it would deadlock with itself, for example by making conflicting requests against the same control interval.
Does AFCF apply to RLS files?
No. IBM describes this detection for VSAM files in non-RLS mode. With RLS, VSAM handles record locks, and a lock wait that runs too long ends in AFCV.
Does the other transaction fail too?
No. Only the task about to close the deadlock is abended. When its updates are backed out its locks are released, and the other task continues.