How can I force a CreateFile call to hang, in order to test something?

Raymond Chen

A customer was doing some testing and wanted to know if there was a way to force a call to Create­File to hang, so that they can test their program’s hang detection and recovery code.

You can ceate these scenarios with careful use of opportunistic locks (also known as oplocks). The sample program I wrote some time ago can be used, for example, to cause a Create­File call requesting write access to hang until the oplock is released.

To cause a Create­File call requesting read access to hang until the oplock is released, use OPLOCK_LEVEL_CACHE_WRITE; this means that the oplock owner is caching writes, so nobody can read from the file until the cached writes are flushed out.

0 comments

Discussion is closed.

Feedback usabilla icon