8

I have a weird situation on a production server.

We have network application written on C++ which serves users requests by TCP written using IOCP.

Two days ago we did an update of Windows 2012 R2 (it installed latest security updates. The previous update was 6 month ago). And after the update when trying to stop the service we see in logs that server hangs on call to close listening socket

closesocket(session->listen_socket);

The schema of stopping the network system is the next:

  1. PostQueuedCompletionStatus(m_completion_port, 0, NULL, NULL); x the number of worker threads

  2. Wait all worker threads finish their job

  3. CloseHandle(m_completion_port);

  4. closesocket(session->accept_socket);

    closesocket(session->listen_socket);

This was working good for the last 4 years, but suddenly after Windows 2012 R2 update the server hangs forever on call closesocket(session->listen_socket);

I've alsi tried as a solution to set LINGER option with 0 timeout to make abotive closure, but it didn't help.

All ideas how to fix this or make any additional diagnostics?

Valentin
  • 860
  • 2
  • 10
  • 21
  • first of all - look stack trace of call `closesocket` - where exactly code hung. are inside call `NtClose` or in another place – RbMm Jul 16 '18 at 13:05
  • @RbMm `ntdll.dll!NtClose()` `mswsock.dll!SockCloseSocket()` `mswsock.dll!WSPCloseSocket()` `ws2_32.dll!closesocket() Unknown` – Valentin Jul 16 '18 at 14:08
  • this mean hang was in kernel mode driver. even don't know what in this situation do next – RbMm Jul 16 '18 at 14:24
  • @RbMm Here is what i've found. https://forum.filezilla-project.org/viewtopic.php?t=49308. Looks like windows security update causing this issue. Will try to remove an update and tell you results – Valentin Jul 16 '18 at 14:33
  • 2
    @RbMm Removing **KB4338815** fixed this issue on all our servers. Thanks for help! – Valentin Jul 16 '18 at 15:05
  • We have experienced this same issue with a sockets based application/service. Will Microsoft have an update of the update? – M Schenkel Jul 17 '18 at 02:43
  • 3
    @MSchenkel See my answer in https://stackoverflow.com/questions/51372116/freezing-winsock-application-after-kb4338830-update/51387161#51387161 for Microsoft's patch for the issue – CSakura Jul 17 '18 at 17:29
  • thank you for cross posting this.. I appreciate it. – M Schenkel Jul 17 '18 at 18:29
  • OMFG, we've been dealing with this for months before I had the good sense to use closesocket in google searches. I hadn't been thinking below the framework (Qt)! Best part is the process eventually dies, but the port remains in use but hidden in the kernel.. – John Neuhaus Oct 17 '18 at 23:31

1 Answers1

6

The issue was brought by patch from Microsoft KB4338815, which caused closesocket tо hang forever on Intel Xeon processors and this was also posted by FileZilla guys in this thread https://forum.filezilla-project.org/viewtopic.php?t=49308

Valentin
  • 860
  • 2
  • 10
  • 21