none
PostThreadMessage fails with "invalid thread id" randomly under load on a container RRS feed

  • Question

  • Hello,

    While load testing a complex application in Windows container, the PostThreadMessage function fails occasionally. When this happens, GetLastError() always returns 0x5A4 "invalid thread id".

    The weird part is that: it works ok for about an hour, it generates one or a couple of these errors and then works ok again. The target thread for the post exists and continues to process messages without any obvious issues.

    We have never seen anything like this - the loads on physical and virtual machines never experienced this issue. Is true that this is the first time we are doing these tests on a container.

    We reproduced this issue in various virtual environments. One environment was: host for VM -> Windows 10, VM -> Windows 2019, base image ->  "OsVersion": "10.0.17763.864", "DockerVersion": "19.03.5"

    Would it be great if someone with kernel knowledge could help us understand the cases when this function will return this error even if the thread is still valid.

    Thank you,

    Bogdan


    Vasilescu Bogdan

    Friday, December 6, 2019 12:30 AM

All replies

  • Hi,

    Thanks for posting here.

    According to your description, this issue is more related to Windows Containers.

    You can ask the question here to get better support.

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=windowscontainers

    In addition, according to the PostThreadMessage document:

    • GetLastError returns ERROR_INVALID_THREAD_ID if idThread is not a valid thread identifier, or if the thread specified by idThread does not have a message queue.
    • This thread must either belong to the same desktop as the calling thread or to a process with the same LUID. Otherwise, the function fails and returns ERROR_INVALID_THREAD_ID.
    • This thread must have the SE_TCB_NAME privilege to post a message to a thread that belongs to a process with the same locally unique identifier (LUID) but is in a different desktop. Otherwise, the function fails and returns ERROR_INVALID_THREAD_ID.

    Best Regards,

    Drake


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 6, 2019 5:30 AM
    Moderator
  • Hi Drake,

    Thank you for taking the time to look over this question.

    While the question is in the context of Windows containers, it is strictly related to PostThreadMessage and its internal [kernel] workings. From what I understood the container and the host are sharing the same kernel.

    This is why it would be great if a MS engineer with experience in this area would provide us with some details and possible ways to continue our investigation.

    Thank you,

    Bogdan


    Vasilescu Bogdan

    Friday, December 6, 2019 4:34 PM
  • Try to call OpenThread before PostThreadMessage, Thread may have been closed, thread ID is invalid. 

    Or check whether there is the situation I mentioned above.

    Best Regards,

    Drake


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 9, 2019 10:04 AM
    Moderator
  • Thank you Drake,

    I made sure the thread is still valid. In fact, after a couple of these errors, calls to PostThreadMessages with same thread id succeed. Moreover, the thread itself continues to process messages.

    Thank you,
    Bogdan


    Vasilescu Bogdan

    Monday, December 9, 2019 5:31 PM
  • Could you provide a small reproducible sample? So that we can provide better support for you.

    Thanks,

    Drake


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 11, 2019 9:19 AM
    Moderator
  • Unfortunately I was not able to reproduce it using a simple application.

    As I mentioned, this is a complex application with tones of modules, multiple layers and combining several frameworks. It is hard to tell if my test application exercises all the parts involved in this issue - most probably is not.

    It would be great if a MS engineer with knowledge of this section of kernel could tell us the cases where this error might be generated so we can concentrate our efforts in that area.

    A detail that might be important: the thread where we are posting the messages that are failing is the thread used for async usage of sockets [WSAAsyncSelect]. The application is constantly creating and destroying the windows for the sockets. In our application we are using > 100 sockets for RTP and RTCP data - meaning we are sending and receiving small packets every 20ms on each socket.

    Could you please tell me if there is any tracing that could be enable to get more data about the issue - some Windows API tracing?

    Thank you,

    Bogdan



    Vasilescu Bogdan

    Wednesday, December 11, 2019 7:18 PM
  • Thanks for your information. I will submit your questions to the relevant engineers internally.

    Please wait patiently here.

    Best Regards,

    Drake


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, December 12, 2019 7:44 AM
    Moderator
  • Hi Bogdan,

    After reviewing the conversion, it is very difficult to find the root cause for this issue. To troubleshoot this issue, we may need more info like dump files, and it is too complex for the forum discussing.

    To resolved this issue as soon as possible, a support ticket is recommend so that our engineers can works closely with you. If the support engineer determines that the issue is the result of a bug the service request will be a no-charge case and you won't be charged. 

    Please visit the below link to see the various paid support options that are available to better meet your needs.

    https://support.microsoft.com/en-us/hub/4343728/support-for-business


    Best regards

    Fei


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 16, 2019 7:43 AM
  • Hi,

    just a wild guess: How many messages are you posting? There's default limit of 10,000 messages per thread.
    It can be changed in HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\USERPostMessageLimit


    Monday, December 16, 2019 3:25 PM
  • Yes, but then one would expect GetLastError to return ERROR_NOT_ENOUGH_QUOTA instead of ERROR_INVALID_THREAD_ID.

    Monday, December 16, 2019 3:30 PM
  • Thank you everyone for your input.

    I knew that the application is not posting too many messages to the queue. Nevertheless, I did a test where I continuously posted messages without processing them. As expected and documented: once the queue reached its limit, it started generating ERROR_NOT_ENOUGH_QUOTA errors.

    At this point I decided to take Fei's advice and opened a support case with MS. Hopefully I will be able to provide some more info once they finish their analysis.

    Thank you,

    Bogdan


    Vasilescu Bogdan

    Tuesday, December 17, 2019 6:09 PM