"0x0000006 The handle is invalid" error coming in multi-threaded environment

-4

I have created an ASP 3.5 web service which performs thumbnail generation using some Windows APIs. These APIs use Windows HANDLE orHFILE for processing. I am using Asynchronous AJAX in JavaScript to call the web-service.

  • Server: ASP 3.5 Web Service
  • Client: AJAX in JavaScript

When I am initiating only 1 request i.e. single thread in web service, no error is coming, but
When I am initiating multiple requests i.e. multiple threads in web service, internal APIs listed below are giving errors randomly without any specific patterns. GetLastError returns error code 0x00000006.

Internal APIs: One Set

  • _llseek
  • _lread

Second Set

  • CreateFileMapping
  • MapViewOfFile

Notes:

  • _llseek and _lread use HANDLE created using

    CreateFile(str, 0x80000000, 0x00000001, IntPtr.Zero, 3, 1, IntPtr.Zero)
    
  • CreateFileMapping and MapViewOfFile use HANDLE created using,

    CreateFile(sThumbnailFile, (uint)(0x80000000 | 0x40000000), 0, IntPtr.Zero, 2, 128, IntPtr.Zero);
    

    no error or INVALID_HANDLE_VALUE return code is coming while creating HANDLE.

  • This issue is occurring randomly in multiple requests.

  • Each HANDLEpoints to a different file.

I have even tested with CRITICAL_SECTION but issue still persists. Please suggest what could be the possible error?

asp.net
multithreading
winapi
asmx
handle
asked on Stack Overflow Dec 18, 2015 by Amber Beriwal • edited Dec 18, 2015 by user692942

1 Answer

-1

I know solution would seem a little weird..but the problem was:
some other HANDLE in some other API was being closed improperly due to which these APIs started giving error at runtime in multi-threaded environment due to shortage of memory or other resource.

Thanks.

answered on Stack Overflow Dec 22, 2015 by Amber Beriwal

User contributions licensed under CC BY-SA 3.0