Connection Closed ERROR on REST call

Connection Closed ERROR on REST call

  

Folks,

I have a BPM process that when started, it makes a series of calls to a 3rd-party REST API to gather data and store it locally in an OutSystems DB table.

The REST call works great on a 1-at-a-time basis ... so, in my loop, I even added a 2 seconds "Sleep".

BUT, I keep getting a random "Connection Close" error.

HELP: I can't tell if the OutSystems server is closing the connection - OR - if the 3rd-party REST API that I am calling is in fact closing the connection.

How can I tell why and where the connection is being closed???

See error message below - thanks!

-Bruce

Id:
e333eb15-e49f-46ee-884d-4bb666c31009
Time of Log:
2018-10-18 14:53:47
eSpace:
H_APIs_Logic
Tenant:
Users
User:

Session Id:

Server:
E3PWG-DV4T2P
Module:
Scheduler
Message:


Scheduler Service: Error executing request http://127.0.0.1/H_APIs_Logic/ for Activity RunReplication. Request duration = 29 secs.


Environment InformationeSpaceVer: 0 (Id=0, PubId=0, CompiledWith=10.0.828.0)
RequestUrl:  (Method: )
AppDomain: Scheduler.exe
Path: C:\...\PS\
Locale:
DateFormat: yyyy-M-d
PID: 792 ('Scheduler', Started='10/4/2018 4:36:41 PM', Priv=38Mb, Virt=636Mb)
TID: 16
Thread Name: Activity Processor #1
.NET\: 4.0.30319.42000
Stack:
The underlying connection was closed: An unexpected error occurred on a receive.
   at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at OutSystems.HubEdition.RuntimePlatform.Processes.ActivityHandler.ExecuteActivityActionv2(String ssKey, Int32 activityId, Int32 processId, Int32 tenantId, ActivityStatus forInitialStatus, DateTime previousNextRun)
   at OutSystems.HubEdition.Scheduler.ActivityJob.Execute()
   at OutSystems.HubEdition.Scheduler.SchedulerProducerConsumer`1.<>c__DisplayClass25_0.<Execute>b__0()

Hi Bruce,

First, it shouldn't be needed to perform a sleep before calling a REST service. Secondly, this is a network error, so unfortunately the problem can be anywhere. If the 3rd party has a helpdesk, I'd be sure to give them a call, and perhaps also check with your local sysadmin in case you're running on-premise (in the cloud you can forget that one).

Kilian Hekhuis wrote:

Hi Bruce,

First, it shouldn't be needed to perform a sleep before calling a REST service. Secondly, this is a network error, so unfortunately the problem can be anywhere. If the 3rd party has a helpdesk, I'd be sure to give them a call, and perhaps also check with your local sysadmin in case you're running on-premise (in the cloud you can forget that one).

Thanks Kilian for the response - interestingly I just moved my "replication process" from BPM into simple Timers and I am NOT getting the "Connection Closed" issues even after taking the "Sleep" out of the loop.

So, there is something about my BPM environment in the OutSystems Enterprise Cloud that I need to open support ticket against.

QUESTION: On a related note, in the replication processing loop the REST response can result intentionally with an exception. It's a "normal exception" that we'll see depending on the data passed in. Without knowing a better way, in the EXCEPTION handler, I want the loop to continue but I don't know how to make that happen. So, I have to "wake" another Timer inside the exception handler. BUT - this is very slow as processing pauses to wait for the new timer instance to "wake". Is there a better/faster way to handle an exception and CONTINUE processing?



Solution

Hi Bruce,

If the connection reset happens on BPT (not BPM :)) but not in a Timer, the only thing I can think of is that the REST call is so slow, that the BPT process is hitting a timeout and kills the connection. But indeed verify with Support.

As for your second question, it is not possible to recover from an Exception in the Action the Exception occurs in. If you do want to continue, you need to wrap the call to the REST service in a seperate Action that includes an Exception Handler, and call that Action in the loop. Thus, the Exception is handled in the Action, and the loop continues.

Solution

Kilian Hekhuis wrote:

Hi Bruce,

If the connection reset happens on BPT (not BPM :)) but not in a Timer, the only thing I can think of is that the REST call is so slow, that the BPT process is hitting a timeout and kills the connection. But indeed verify with Support.

As for your second question, it is not possible to recover from an Exception in the Action the Exception occurs in. If you do want to continue, you need to wrap the call to the REST service in a seperate Action that includes an Exception Handler, and call that Action in the loop. Thus, the Exception is handled in the Action, and the loop continues.


Thanks for the advice!!!

I did two things and now the process is FLYING!!!!

1) Moved the REST call into a separate Server Action and did the exception handling there - this way as you stated, the loop could continue! Brilliant, why didn't I think of that before?!?!?

2) Switched from BPT to a Timer ... still need to figure out why the BPT was getting a closed connection but that is for our good support folks and not critical right now.


Thanks again!

Hi Bruce,

Great to hear you got everything running :). Happy coding!