What does a STATUS_OBJECT_TYPE_MISMATCH exception in LeaveCriticalSection mean?

It means the same thing as a STATUS_INVALID_HANDLE exception.

Comments (10)
  1. Wow, that was concise!

    How come we don't get a time-machine requiring thermal nuclear social skill explanation of why these are the different if they are the same?

  2. Anonymous says:

    @Lockwood: I guess they are not exactly the same.  A critical section may contain a (keyed) event handle.  The invalid handle error means that the handle is completely invalid and doesn't reference anything.  The object type mismatch error means that the handle is a valid handle but doesn't refer to a (keyed) event.

    But they both mean "the handle is wrong" and the root causes are the same.

  3. It's one last step away from getting really unlucky, where the previously released event handle has been assigned to another event, and your call "succeeds".

  4. @laonianren: I don't know anything about critical sections; I live in .NET land, and enjoy Raymond's writings about the OS.

    If these are 2 cases which lead to the same end point, "the handle is wrong", and they both have the same root cause, why have 2 messages and not a slightly fluffier one to cover both? STATUS_OBJECT_TYPE_MISMATCH_OR_INVALID_HANDLE? Or similar but shorter.

  5. Anonymous says:

    Because distinguishing "that is not a handle" and "that is a handle but not the right type of handle" may sometimes be useful to programmers.

  6. Anonymous says:

    STATUS_OBJECT_TYPE_MISMATCH_OR_INVALID_HANDLE reminds me of the SQL error message "String or binary data would be truncated".  I hate that message.

    The storage engine knows whether STRING data or BINARY data would be truncated, but it refuses to tell you which.  It also doesn't tell you the other crucial piece of useful information, which is the name of the relevant column.  Sometimes it's very tedious to figure this out.

  7. Anonymous says:

    For Windows 8, we've "electrified the fences" a bit in the kernel and instituted the policy to make accessing an invalid handle throw an immediate exception. The policy is always on for Metro apps. You can use the SetProcessMitigationPolicy API (msdn.microsoft.com/…/hh769088(v=vs.85).aspx) to enable this on existing desktop apps.

  8. Anonymous says:

    Let's just say that getting any error out of LeaveCriticalSection means you have screwed up royally.

  9. Anonymous says:

    @David Walker, IE always annoyed me when it came up with something like "Cannot connect to server or DNS error."  So is that site down, or the whole Internet broken?

    Older MySQLs had the unhelpful message, "Duplicate entry in key 2."  Which lets the DBA use SHOW INDEX to figure out the affected column, but by then the user is gone, and so is the value they were trying to insert.

  10. @Lockwood When you put on your kernel-colored glasses (blogs.msdn.com/…/10163578.aspx), they are different errors noticed by different components for different reasons. This LeaveCriticalSection condition is all about "exploring" undefined behavior and seeing which error case you happen to hit (if you are lucky enough to hit an error case).

Comments are closed.