User logoff does not release SMB connections on Windows Server

Kiki Julia Smith 65 Reputation points
2026-11-27T15:14:48.3833333+00:00

Issue: SMB sessions and associated file handles are not released when users sign out of their Windows workstations.

Expected behavior: SMB connections associated with the terminated user session should eventually be closed, provided no other processes require them.

Actual behavior: The file server continues to maintain SMB sessions and open file handles after user logoff.

Question: What determines the lifecycle of an SMB session on Windows Server? Are there specific PowerShell commands, event logs, or diagnostic tools that can help identify why these connections remain active and what is preventing their automatic cleanup?

Windows for business | Windows Server | Networking | Network connectivity and file sharing
0 comments No comments

2 answers

Sort by: Most helpful
  1. Jason Nguyen Tran 31,625 Reputation points Independent Advisor
    2026-11-27T16:00:28.64+00:00

    Hi Kiki Julia Smith,

    The short answer is that logging off doesn't automatically close the SMB session. The session stays open as long as anything on the workstation is still using it. It could be a service running under that user's account, a backup or sync agent, antivirus, or a scheduled task. Any of these can keep the connection alive in the background after the user signs out.

    On the file server, I'd start with Get-SmbOpenFile | Select ClientComputerName, ClientUserName, Path, which shows which machines and files are still holding handles. Then go to one of those workstations and run Get-SmbConnection, or open Sysinternals Process Explorer and search for the share path to see which process still has it open. That usually points straight to the cause.

    It's also worth checking AutoDisconnectTimeout in Get-SmbServerConfiguration, which controls when idle sessions are dropped. And if you're using Continuously Available shares, keep in mind that persistent handles are meant to stay open for a while after a disconnect. The SMBServer/Operational log in Event Viewer can help confirm exactly when sessions open and close. If you just need to clean things up for now, Close-SmbSession will do it, but the connections will come back until you deal with the process that's holding them.

    I hope the response provided some helpful insight. If you find this answer useful, please hit “accept answer” so I know it addressed your concern.

    Jason

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-11-27T15:15:50.78+00:00

    A Windows interactive sign-out does not itself define an SMB session’s lifetime; determine whether the client still has an open, whether it sent SMB2 LOGOFF or closed the transport, and whether the server is preserving a durable or resilient handle.

    How SMB session cleanup works

    An SMB session ends through SMB protocol activity rather than directly through the Windows interactive-logon lifecycle:

    • A client can send an SMB2 LOGOFF request for a particular SMB session.^1^
    • When the server receives LOGOFF, it removes and frees the session. Ordinary opens are closed, but durable opens can be detached and retained temporarily for reconnection.^2^
    • Idle cleanup occurs only when the client session’s open table is empty and its idle timeout has expired. The client may then tear down the connection without explicitly sending LOGOFF.^3^
    • After transport loss, a durable handle is intentionally retained for at least its durable-handle timeout. The server’s scavenger closes it only after the configured time has elapsed and the client has not reclaimed it.^4^

    Consequently, a remaining entry can indicate an active process or service, a different credential/logon context, an unexpired durable/resilient handle, or a connection that has not yet reached idle-cleanup conditions. Multiple SMB connections from one workstation can also exist independently.

    Inspect the state on the file server

    Run these commands in an elevated PowerShell session on the SMB server:

    $user = 'CONTOSO\User1'
    
    $sessions = Get-SmbSession -ClientUserName $user -IncludeHidden
    $sessions | Select-Object SessionId, ClientComputerName, ClientUserName,
        NumOpens, SecondsExists, SecondsIdle, Dialect
    
    foreach ($session in $sessions) {
        Get-SmbOpenFile -SessionId $session.SessionId |
            Select-Object SessionId, FileId, ClientComputerName, ClientUserName,
                ShareRelativePath, Locks, ContinuouslyAvailable
    }
    

    Get-SmbSession exposes the client, user, number of opens, session age, and idle time; -IncludeHidden also includes internally used sessions.^5^ Get-SmbOpenFile correlates each open with its session, client, user, path, lock count, and continuous-availability state.^6^

    Interpret the results as follows:

    • NumOpens greater than zero: inspect the corresponding paths and locks.
    • Increasing SecondsIdle: no current SMB operations are reaching that session, although retained opens may still prevent ordinary idle teardown.
    • ContinuouslyAvailable = True: investigate durable/persistent-handle behavior rather than assuming that the handle is orphaned.
    • Unexpected user or computer account: a service, scheduled task, or application may be using another logon context.

    On the workstation, run:

    Get-SmbConnection |
        Select-Object ServerName, ShareName, UserName, Credential,
            NumOpens, Dialect, ContinuouslyAvailable
    

    The client reports connections per share, user logon, and credential. This is important because SMB credentials can differ from the interactive user’s credentials.^7^ Correlate these results with running services, scheduled tasks, backup agents, synchronization software, shells, and applications on the named workstation. The server-side SMB objects identify the retaining client and security context, but do not directly name the client process.

    Event logs and auditing

    Review the same time window on both systems under:

    • Applications and Services Logs → Microsoft → Windows → SMBClient
    • Applications and Services Logs → Microsoft → Windows → SMBServer

    These logs contain connection, authentication, share-access, and protocol-negotiation information.^8^

    If file-share auditing is enabled, correlate Security event 5145 by account, source IP/port, share, and requested path. Detailed File Share auditing records every file/folder access and can produce high event volume on file servers.^9^

    Capture the decisive protocol evidence

    If PowerShell and logs do not show why teardown is delayed, capture simultaneous client/server traces around sign-out:

    mkdir C:\Temp
    netsh trace start capture=yes report=yes scenario=NetConnection level=5 maxsize=1024 tracefile=C:\Temp\netTrace.etl
    rem Reproduce: access the share, sign out, and wait for the observed condition.
    netsh trace stop
    

    Microsoft recommends collecting both sides and limiting the capture duration.^10^ Check whether the client sends SMB2 CLOSE, TREE_DISCONNECT, or LOGOFF, closes the TCP connection, reconnects under another credential, or attempts to reclaim a durable handle.

    Administrative cleanup

    After confirming that the session is stale and no application still needs it:

    Close-SmbSession -SessionId 8813272891621 -WhatIf
    Close-SmbSession -SessionId 8813272891621
    

    This forcibly ends the entire session and may lose unflushed client data.^11^ To close only a selected handle, use Close-SmbOpenFile -FileId <id>; it carries the same data-loss risk.^12^


    References

    1. 2.2.7 SMB2 LOGOFF Request
    2. [IP Address] Receiving an SMB2 LOGOFF Request
    3. [IP Address] Idle Connection Timer Event
    4. [IP Address] Durable Open Scavenger Timer
    5. Get-SmbSession-Description
    6. Get-SmbOpenFile-Description
    7. Get-SmbConnection-Description
    8. What is SMB File Sharing for Windows and Windows Server?
    9. Advanced Audit Policy Configuration
    10. Advanced Troubleshooting Server Message Block (SMB)
    11. Close-SmbSession-Syntax
    12. Close-SmbOpenFile-Description
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.