REST C# API - WebClient connection closed exception

We are using the C# REST API to submit actions and on occasion we are seeing an exception being thrown:

An exception occurred during a WebClient request. Unable to read data from the transport connection. The connection was closed.

This happens during Bresults = client.UploadData(resourceURI, bytes); in the postRest method.
I have found resources on StackOverflow that suggest extending the WebClient and setting the timeout and ProtocolVersion, but this even using this extended WebClient we still see the problem.

This exception is not thrown every time and out of 20 or 30 actions submitted we may only see it pop up once, but due to the nature of the actions being submitted we need to ensure that we have a way to address this. The action being submitted is always the same one using a sourced fixlet the only difference is the targets and parameters, so there’s no issue with it only happening certain fixlets or actions.

Because of the exception we have no way of knowing whether the action was submitted successfully or not. If I verify the action was submitted by checking the console, I see that it was submitted every time, so it seems that it’s an issue with the connection just being closed before a result is returned, but I don’t now how to correct that. We need the result because we need the Action Id in order to track progress.

Any help is greatly appreciated.

You might want to check the BESRelay.log on the server to see if there is an explanation for the error other than an intermittent network issues. You could also try to recreate the problem using our CLI (iem.exe) to see if it is specific to the system or your app.

As a workaround, you could query for the highest action ID on the server prior to submitting yours, and if this error occurs, you can query again for newer action IDs with the name included in your POST request. Relevance to use on the query call would be something like:

ids of bes actions whose (id of it > XX and name of it equals "Submitted action name")

Thanks for the feedback. I’ll look into the BESRelay.log

Unfortunately WebReports is running on a different server so there’s a brief lag. I already tried using a relevance query to lookup the action in the event that we got the exception, but unfortunately because it takes a minute or two for the WebReports server to sync up and see the action the relevance comes back as if the action doesn’t exist.