PRB: WSACancelAsyncRequest Causes a Memory Access Violation

Last reviewed: November 29, 1995
Article ID: Q140166
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) versions 3.51, 4.0

SYMPTOMS

An application that uses the WinSock 1.1 call WSACancelAsyncRequest occasionally throws memory exceptions or causes erratic behavior.

CAUSE

WSACancelAsyncRequest has unavoidable timing conflicts that make canceling calls in progress impossible. WSACancelAsyncRequest is only successful at stopping calls queued for processing that have not yet started.

RESOLUTION

Don't use WSACancelAsyncRequest to cancel calls that may be in progress. Specifically, don't try to cancel asynchronous selects. Allow them to complete, and ignore the results if necessary.

STATUS

This behavior is by design.

MORE INFORMATION

When an asynchronous WinSock call is in progress, it is hard to stop. For example, an outstanding WSAAsyncSelect call may be in the process of writing to a buffer your application supplied. The sockets DLL has no way of terminating a memory copy because of the timing windows generated by multiple threads. One thread may be in the middle of copying while another does the cancel.

The best way to cancel asynchronous events is to allow them to complete, but ignore the results. For WSAAsyncSelect, you might set a status flag, and when the select message is processed by your window procedure, you can check the status flag, ignoring the message if the flag is set.


Additional reference words: 4.00
KBCategory: kbnetwork kbtshoot kbprb
KBSubcategory: kbntwkmisc


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.