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
- 2.2.7 SMB2 LOGOFF Request
- [IP Address] Receiving an SMB2 LOGOFF Request
- [IP Address] Idle Connection Timer Event
- [IP Address] Durable Open Scavenger Timer
- Get-SmbSession-Description
- Get-SmbOpenFile-Description
- Get-SmbConnection-Description
- What is SMB File Sharing for Windows and Windows Server?
- Advanced Audit Policy Configuration
- Advanced Troubleshooting Server Message Block (SMB)
- Close-SmbSession-Syntax
- Close-SmbOpenFile-Description