TMS-Sparkle crashes with IOHandler (e.g. TaurusTLS) under Linux

Hello,
I am using TMS-Sparkle with Indy server an TaurusTLS.Somtimes the server crashes, when the client is killed (e.g. by the TaskManager). In this case the IOHandler (e.g. TaurusTLS closes the connetion, but "TIndyResponse.EndResponse" still tries to send the response with "TIdHTTPResponseInfo.WriteContent".

See:
Server crashes with NetHTTPClient and TIdHTTPResponseInfo.WriteContent · Issue #224 · TaurusTLS-Developers/TaurusTLS

I changed the code in “Sparkle.Indy.Context” and it seems to work. Please check it:


TIndyResponse = class(THttpServerResponse)
strict private
FResponse: TIdHTTPResponseInfo;
FIdContext: TIdContext; // <-- new
FStream: TStream;
strict protected
procedure EndResponse; override;
procedure SendResponse; override;
function SendBody(const PBuf: Pointer; const BufferSize: Integer): Integer; override;
public
constructor Create(AResponse: TIdHTTPResponseInfo; AIdContext: TIDContext); // <-- AIdContext new
destructor Destroy; override;
end;
...
constructor TIndyContext.Create(AThread: TIDContext;
ARequest: TIdHTTPRequestInfo; AResponse: TIdHTTPResponseInfo);
begin
inherited Create;
FThreadContext := AThread;
FRequest := TIndyRequest.Create(ARequest, AThread);
FResponse := TIndyResponse.Create(AResponse, AThread); // <-- AThrad new
end;

constructor TIndyResponse.Create(AResponse: TIdHTTPResponseInfo; AIdContext: TIDContext);
begin
inherited Create;
FResponse := AResponse;
FIdContext := AIdContext; // <-- new
FStream := TMemoryStream.Create;
FResponse.FreeContentStream := False;
end;

destructor TIndyResponse.Destroy;
begin
FreeAndNil(FStream);
inherited;
end;

procedure TIndyResponse.EndResponse;
begin
if FIdContext.Connection.Connected = False then Exit; // <-- new

FResponse.WriteContent;
FStream.Position := 0;
end;

Thank you, we will include this fix in the next release.