Hi Sergio, I'm using an HTTP2 client (TsgcHTTP2Client) to connect to my REST service (Datasnap) and I'm having a problem.
If I create post requests too close together, the flow throws errors, almost always during disconnection, such as "Thread Error: Invalid Handle (6)" or an access violation. To make everything work correctly, I need to insert a sleep(1000) between each call. Do you have any idea what could be causing the error? Am I doing something wrong? I've attached the function that's giving the error:
function TGesanLicensingRestClient.PostAction(const Params: TActionRest): TResponse;
begin
Result.ValueResult := nil;
Result.StatusCode := UNREACHABLE;
var RESTRequest := TStringStream.Create;
var RESTResponse := TStringStream.Create;
try
if Params.IsJSONValue then begin
RESTRequest.WriteString(Params.ToString);
if PrepareAction or BeginHttpNegotiation(FRESTClient,ROOT_EP,True) then begin
FRESTClient.Connect;
FRESTClient.Post(FRESTClient.Host + '/' + Params.Action, RESTRequest, RESTResponse);
if (FRESTClient.Response.Status = NO_ERROR) and IsJsonValue(RESTResponse.DataString) then begin
var JsRes := AsJsonObject(RESTResponse.DataString);
if Assigned(JsRes.FindValue('result')) then begin
var JsSubRes := JsRes.Values['result'] as TJSONArray;
Result.StatusCode := TJSONObject(JsSubRes.Items[0]).values['errorcode'].value.ToInteger;
Result.ErrorDescription := TJSONObject(JsSubRes.Items[0]).values['errordescription'].value;
Result.ValueResult := JsSubRes.Items[0].Clone;
JsRes.Free;
end;
end
else begin
Result.StatusCode := FRESTClient.Response.Status;
Result.ErrorDescription := RESTResponse.DataString;
end;
end;
FRESTClient.Disconnect;
end;
except
on e: Exception do
Result.ErrorDescription := e.Message;
end;
RESTRequest.Free;
RESTResponse.Free;
end;
Thanks so much for the support.
If I create post requests too close together, the flow throws errors, almost always during disconnection, such as "Thread Error: Invalid Handle (6)" or an access violation. To make everything work correctly, I need to insert a sleep(1000) between each call. Do you have any idea what could be causing the error? Am I doing something wrong? I've attached the function that's giving the error:
function TGesanLicensingRestClient.PostAction(const Params: TActionRest): TResponse;
begin
Result.ValueResult := nil;
Result.StatusCode := UNREACHABLE;
var RESTRequest := TStringStream.Create;
var RESTResponse := TStringStream.Create;
try
if Params.IsJSONValue then begin
RESTRequest.WriteString(Params.ToString);
if PrepareAction or BeginHttpNegotiation(FRESTClient,ROOT_EP,True) then begin
FRESTClient.Connect;
FRESTClient.Post(FRESTClient.Host + '/' + Params.Action, RESTRequest, RESTResponse);
if (FRESTClient.Response.Status = NO_ERROR) and IsJsonValue(RESTResponse.DataString) then begin
var JsRes := AsJsonObject(RESTResponse.DataString);
if Assigned(JsRes.FindValue('result')) then begin
var JsSubRes := JsRes.Values['result'] as TJSONArray;
Result.StatusCode := TJSONObject(JsSubRes.Items[0]).values['errorcode'].value.ToInteger;
Result.ErrorDescription := TJSONObject(JsSubRes.Items[0]).values['errordescription'].value;
Result.ValueResult := JsSubRes.Items[0].Clone;
JsRes.Free;
end;
end
else begin
Result.StatusCode := FRESTClient.Response.Status;
Result.ErrorDescription := RESTResponse.DataString;
end;
end;
FRESTClient.Disconnect;
end;
except
on e: Exception do
Result.ErrorDescription := e.Message;
end;
RESTRequest.Free;
RESTResponse.Free;
end;
Thanks so much for the support.