Page 1 of 1

Error on data reading from the connection: An existing connection was forcibly closed by the remote host

Posted: Sun 19 Apr 2020 16:41
by DmitriNL
In this topic (viewtopic.php?f=27&t=40513) I was exploring the SecureBridge HTTP component possibilities. After implementing TScHttpWebRequest in my project I receive again an exception. The exception occurs when TScHttpWebRequest is called several times in a short period of time. Below you find the exception message.

The exception message is

Code: Select all

Project Project1.exe raised exception class Exception with message 'Error on data reading from the connection: 
An existing connection was forcibly closed by the remote host'.
A dirty solution is to catch the exception and recall the request. In my opinion, code below is a dirty method. It is a dirty method because I need to search for the error message as a String instead of a specific Exception class like HttpException. My solution below could end up in an endless loop. (I understand that it is possible to count the recalls and do something after the maximum count is reached).

Code: Select all

void __fastcall TMyProject::Get(String AUrl, TStringStream *&AResponseContent)
{
	try
	{
		TScHttpWebRequest *Request = new TScHttpWebRequest(AUrl);
		try
		{
			Request->UserAgent = this->UserAgent;
			Request->Method = rmGET;
			Request->ConnectionGroupName = "my_group_name";
			TScHttpWebResponse *Response = Request->GetResponse();
			try
			{ 
				Response->ReadToStream(AResponseContent);
			}
			__finally
			{
				Response->Free();
			}
		}
		__finally
		{
			Request->Free();
		}
	}
	catch (HttpException &exception)
	{
		// nothing is fetched here
	}
	catch (Exception &exception)
	{		
		if(exception.Message.Pos("An existing connection was forcibly closed by the remote host") > 1)
		{
			this->Get(AUrl, AResponseContent);
		}
	}
}
// ---------------------------------------------------------------------------
I am wondering if there is another method for handling the error message. Can you please inform me what to do? Thank you in advance for your support.

Re: Error on data reading from the connection: An existing connection was forcibly closed by the remote host

Posted: Tue 21 Apr 2020 14:22
by ViktorV
You've found the only possible way to handle this exception at the moment. We'll change the exception type to SocketException in the next build.

Re: Error on data reading from the connection: An existing connection was forcibly closed by the remote host

Posted: Wed 22 Apr 2020 16:25
by DmitriNL
A specific exception type would be great. Thank you for your support.

Re: Error on data reading from the connection: An existing connection was forcibly closed by the remote host

Posted: Fri 24 Apr 2020 10:03
by ViktorV
Thank you for the interest to our product.
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.