Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TCPServer crash on shutdown
#9
(08-06-2018, 09:18 PM)rlebeau Wrote: On Windows, it is overridden by the TIdStackWindows.Disconnect() method, which simply calls the Winsock API shutdown() and closesocket() functions:

Code:
function TIdStackWindows.WSShutdown(ASocket: TIdStackSocketHandle; AHow: Integer): Integer;
begin
 Result := Shutdown(ASocket, AHow); // <-- Winsock API call
end;

function TIdStackWindows.WSCloseSocket(ASocket: TIdStackSocketHandle): Integer;
begin
 Result := CloseSocket(ASocket); // <-- Winsock API call
end;

procedure TIdStackWindows.Disconnect(ASocket: TIdStackSocketHandle);
begin
 // Windows uses Id_SD_Send, Linux should use Id_SD_Both
 WSShutdown(ASocket, Id_SD_Send);
 // SO_LINGER is false - socket may take a little while to actually close after this
 WSCloseSocket(ASocket);
end;

Neither of those API functions should be hanging by default, though closesocket() CAN hang if you have configured the socket beforehand with a non-zero linger timeout (which Indy doesn't do, but users can do manually) and pending data is not being sent to the peer correctly.

So I extended my error logging deeper and CloseSocket(ASocket) is where it hangs when TCPServer is trying to close down the first listening thread. I've modified WSCloseSocket() as such:

Code:
function TIdStackWindows.WSCloseSocket(ASocket: TIdStackSocketHandle): Integer;
begin
 LogData.AddError('TIdStackWindows.WSCloseSocket(' + IntToStr(ASocket) + ') Start', True);
 try
 Result := CloseSocket(ASocket);
 except
   on E: Exception do
   begin
     LogData.AddError('WSCloseSocket Exception: ' + E.Message);
     raise;
   end;
 end;
 LogData.AddError('TIdStackWindows.WSCloseSocket(' + IntToStr(ASocket) + ') Stop', True);
end;

And when it does crash, my log only records that start entry like this:

TIdStackWindows.WSCloseSocket(10384) Start

No exception fires and it never reaches my "Stop" log.  I don't know what to do now. You mentioned "non-zero linger timeout". I don't know what that is and so pretty sure I didn't do that. And it's definitely not a stack size issue as I've returned it to the default 1MB setting.
Reply


Messages In This Thread
TCPServer crash on shutdown - by kbriggs - 08-05-2018, 07:50 PM
RE: TCPServer crash on shutdown - by rlebeau - 08-06-2018, 09:18 PM
RE: TCPServer crash on shutdown - by kbriggs - 08-07-2018, 12:07 AM
RE: TCPServer crash on shutdown - by rlebeau - 08-07-2018, 12:53 AM
RE: TCPServer crash on shutdown - by kbriggs - 08-07-2018, 03:10 AM
RE: TCPServer crash on shutdown - by rlebeau - 08-07-2018, 06:45 PM
RE: TCPServer crash on shutdown - by kbriggs - 08-07-2018, 07:36 PM
RE: TCPServer crash on shutdown - by kbriggs - 08-09-2018, 09:53 PM
RE: TCPServer crash on shutdown - by kbriggs - 08-07-2018, 11:47 PM
RE: TCPServer crash on shutdown - by kbriggs - 08-10-2018, 12:13 AM
RE: TCPServer crash on shutdown - by rlebeau - 08-11-2018, 12:35 AM
RE: TCPServer crash on shutdown - by kudzu - 08-10-2018, 02:59 PM
RE: TCPServer crash on shutdown - by kbriggs - 08-12-2018, 08:33 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)