(Republishing, or using this info in a commercial product/website, is prohibited without permission. All other uses are permitted. If in doubt, please ask.)

PREEMPTIVE_OS_CLOSEHANDLE

(Back to main page…)

Description:

This wait type is when a thread is calling the Windows CloseHandle function.

(Books Online description: N/A)

Questions/comments on this wait type? Click here to send Paul an email, especially if you have any information to add to this topic.

Added in SQL Server version:

2008

Removed in SQL Server version:

N/A

Extended Events wait_type value:

The map_key value in sys.dm_xe_map_values is 443 in 2008 and 2008 R2, 491 in 2012, and 507 in 2014 RTM. After 2014 RTM, you must check the DMV to get the latest value as some map_key values have changed in later builds.

Other information:

I have not seen this wait type be a noticeable contention point.

Note that when a thread calls out to Windows, the thread changes from non-preemptive (SQL Server controls the thread) to preemptive (Windows controls the thread) mode. The thread’s state will be listed as RUNNING, as SQL Server doesn’t know what Windows is doing with the thread.

Known occurrences in SQL Server (list number matches call stack list):

  1. Close a file handle (in this case, closing a backup file after completing a BACKUP operation)
  2. Close a file handle (in this case, after altering a FILESTREAM column as part of an ALTER TABLE … ALTER COLUMN operation)

And other similar stacks.

Abbreviated call stacks (list number matches known occurrences list):

  1. SOS_Task::PopWait+b1
    AutoSwitchPreemptive::~AutoSwitchPreemptive+95
    BackupDiskFile::CloseMedia+11f
    BackupFile::Close+173
    BackupMediaIo::Close+1b7
    BackupStream::DoClose+48
    BackupStream::ThreadMainRoutine+153
    BackupThread::ThreadBase+51
    SubprocEntrypoint+a7f
    SOS_Task::Param::Execute+21e
    SOS_Scheduler::RunTask+ab
  2. SOS_Task::PopWait+b1
    AutoSwitchPreemptive::~AutoSwitchPreemptive+95
    TreeScan::Cleanup+173
    SEDropRowsetColumns+1119
    DDLAgent::SEDropRowsetColumns+65
    CIndexDDL::AlterColumnInBaseIndex+788
    CTableAlter::AlterColumn+b56
    CStmtAlterTable::XretExecute+1a81
    CMsqlExecContext::ExecuteStmts<1,1>+427
    CMsqlExecContext::FExecute+a43
    CSQLSource::Execute+86c
    process_request+a57
    process_commands+4a3
    SOS_Task::Param::Execute+21e
    SOS_Scheduler::RunTask+ab