Problem: Completed print jobs remain visible in Samba print queues after upgrading to UCS 5.2-6

Problem

After upgrading from UCS 5.2-5 to UCS 5.2-6 with Samba 4.24.2, completed print jobs may remain visible in Windows/Samba print queues although CUPS has already processed them successfully.

For an affected printer, CUPS reports no active jobs:

lpstat -W not-completed -o <PRINTER>

while Samba still returns completed jobs:

rpcclient localhost -U Administrator -c 'enumjobs <PRINTER>'

/var/log/samba/log.rpcd_spoolss contains messages such as:

fetch_share_cache_time: Error fetching timing data for [<PRINTER>]. Err:Success
print_cache_expired: Unable to get last scan timing for <PRINTER>

Investigation

Check the relevant Samba printing database:

python3 - <<'PY'
import os
import tdb

printer = "<PRINTER>"
path = f"/var/cache/samba/printing/{printer}.tdb"
db = tdb.Tdb(path, flags=os.O_RDONLY)

for key in (
    b"INFO/version\x00",
    f"CACHE/{printer}\x00".encode(),
    f"MSG_PENDING/{printer}\x00".encode(),
):
    try:
        value = db[key]
        print(key.rstrip(b"\0").decode(), len(value), value.hex())
    except KeyError:
        print(key.rstrip(b"\0").decode(), "missing")

db.close()
PY

The affected state looks like this:

INFO/version 4 09000000
CACHE/<PRINTER> 4 ...

The database is already version 9, but the existing CACHE/<PRINTER> value still uses the old 4-byte format.

Root Cause

Samba 4.21 uses print database version 8 with 32-bit timing values.

After upgrading to Samba 4.24.2, the first access to an existing print database changes INFO/version from 8 to 9, but an existing 4-byte CACHE/<PRINTER> record is not migrated or removed.

Samba 4.24.2 expects this value in the new 8-byte format. Reading the old record fails, preventing the print cache from being refreshed correctly. Completed CUPS jobs can therefore remain in the Samba queue.

:bulb: See here for the bugreport.

Solution

As a workaround, remove only the obsolete CACHE/<PRINTER> record. Samba recreates it in the correct 8-byte format.

First verify that CUPS has no active jobs for the printer:

lpstat -W not-completed -o <PRINTER>

If the output is empty, stop Samba and create a backup:

systemctl stop samba-ad-dc
cp -a /var/cache/samba/printing/<PRINTER>.tdb /root/<PRINTER>.tdb.backup

Remove only the affected cache record:

python3 - <<'PY'
import tdb

printer = "<PRINTER>"
path = f"/var/cache/samba/printing/{printer}.tdb"
db = tdb.Tdb(path)

key = f"CACHE/{printer}\x00".encode()
value = db[key]
print("removing:", len(value), value.hex())
del db[key]

db.close()
PY

Start Samba again:

systemctl start samba-ad-dc

Verify that stale jobs disappear:

rpcclient localhost -U Administrator -c 'enumjobs <PRINTER>'

The recreated cache record should now use 8 bytes:

python3 - <<'PY'
import os
import tdb

printer = "<PRINTER>"
path = f"/var/cache/samba/printing/{printer}.tdb"
db = tdb.Tdb(path, flags=os.O_RDONLY)

key = f"CACHE/{printer}\x00".encode()
value = db[key]
print(key.rstrip(b"\0").decode(), len(value), value.hex())

db.close()
PY

Expected result:

CACHE/<PRINTER> 8 ...

This is a workaround for the affected print database state, not a permanent fix for the upgrade issue.

This topic was automatically closed after 24 hours. New replies are no longer allowed.