Jump to content

SimonB

Members
  • Content Count

    1
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. I am hoping someone can give me a few pointers on the correct way to use TSslHttpRest.RestRequest inside a thread. I am using ICS's TSslHttpRest (v9.5 / Delphi 12.3) inside a thread to talk to a REST API, the program has a few threads running at the same time that gather data in the background threads then post it off to diffrent APIs. To do this I am using RestRequest with the AsyncReq param set to False. http.RestRequest(httpPOST, 'https://sample.com', { * async * } False, param); This works 99.999% of the time and eveything is happy but on one users PC the threads will lockup about once a week or so, and I tracked it down to ICS, or more likely how I am using it. The DNS lookup is failing or timing out (not an ICS issue, its a hardware issue) and this is hanging ICS's DNS Lookup applicaton wide, not just the thread it fails in. Leaving them at the httpDnsLookup state. The tread that hangs goes to httpAborting inside the RestRequest. Here is a minimum example of how I am using TSslHttpRest, (actual code is inside a TThread) TThread.CreateAnonymousThread( procedure var http: TSslHttpRest; threadId: Cardinal; begin http := TSslHttpRest.Create(nil); try http.MultiThreaded := True; http.RestRequest(httpGET, 'https://jsonplaceholder.typicode.com/todos', False); //http.MessageLoop; finally http.Free; end; // Log the thread finishing threadId := GetCurrentThreadId; TThread.Synchronize(nil, procedure begin Memo1.Lines.Add(Format('Thread %d completed', [threadId])); end); end).Start; In the code for TWSocket it says But if I call TSslHttpRest.MessageLoop after TSslHttpRest.RestRequest it never returns. If I dont call it it all works are expected for the 99.999% of the time. But if I don't call it the call to TSslHttpRest.Free can hang when there has been a DNS issue. Due to TIcsAsyncDnsLookupThread.Execute calling SendMessage and waiting for the TSslHttpRest control to process it but without MessageLoop it never will. The call to TSslHttpRest.Free then tries to free its TIcsAsyncDnsLookupThread using UnRegisterIcsAsyncDnsLookup, but that theads is waiting for a responce form SendMessage so never finishes. and GThreadLocalStore is now locked so other threads can not use it. How can I use TSslHttpRest.MessageLoop and have it return so I can safely free the TSslHttpRest object?
×