Skip to content

Instantly share code, notes, and snippets.

@ivan
Created January 10, 2026 06:35
Show Gist options
  • Select an option

  • Save ivan/e7662520c1f62aa9e1a214218c9daa3f to your computer and use it in GitHub Desktop.

Select an option

Save ivan/e7662520c1f62aa9e1a214218c9daa3f to your computer and use it in GitHub Desktop.
Samba 4.22.x directory leases cause outdated directory listings (ChatGPT 5.2 Thinking slop)

after upgrading to NixOS 25.11, Samba returns outdated directory listings not showing new files. my client is an updated Windows 10 ESU. search for bugs in both nixpkgs and samba, need to fix. seems like it's cached for like a minute or so?

ChatGPT said:

Thought for 2m 36s

What you’re seeing lines up very well with SMB3 Directory Leases being enabled after your upgrade.

Why it started after NixOS 25.11

NixOS 25.11 ships Samba 4.22.x (e.g. 4.22.5 in stable 25.11). GitHub
Samba 4.22 introduced “SMB3 Directory Leases” and enables them by default on non-clustered installs. Samba+1

Directory leases let the Windows client cache directory listings. Samba+1
If files are created/renamed outside of SMB (locally on the server by a service, rsync, download tool, etc.), Samba may not revoke the lease promptly, so Explorer keeps showing an old listing until the lease times out / gets invalidated. This exact “minutes later it appears” behavior has been reported, and disabling directory leases fixes it. Samba Mailing Lists+1

(And Samba’s own interoperability docs explicitly note that inotify change notifications are not used to break leases; local changes can therefore be a problem unless you change caching/locking behavior.) SambaWiki


Fast fix (recommended): disable SMB3 directory leases

In smb.conf, set:

  • smb3 directory leases = no Samba+1

NixOS config example

Use whichever style you already use:

Option A (module settings):

nix

Copy code

services.samba = { enable = true; settings = { global = { "smb3 directory leases" = "no"; }; }; };

Option B (extraConfig):

nix

Copy code

services.samba.extraConfig = '' smb3 directory leases = no '';

Then sudo nixos-rebuild switch.

After that, on Windows, close/reopen Explorer windows (or disconnect/reconnect the share) so it drops the cached lease state.


If you want to keep caching (trade-offs)

The man page notes directory leases only apply when smb2 leases=yes, oplocks=yes, and kernel oplocks=no. Samba
So another way to avoid directory leases is setting kernel oplocks = yes, which also helps Samba notice some local modifications via kernel leases — but it comes with behavior/perf trade-offs and disables some advanced SMB2 caching features. SambaWiki+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment