EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Weird TElRestClient behaviour

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
Posted: 10/12/2015 09:44:41
by OGAlex (Standard support level)
Joined: 06/08/2015
Posts: 13

My code is in a PCL targeting Windows Phone 8.1. I'm testing using the emulator. WinStore assemblies,

I've got some strange things happening using my rest client. I'm building a flow that's based on one 400 bad request triggering some new requests, and this flow is only partially implemented. However, after one test, I start getting errors, even if stop and restart the app.

First I get:

EElHTTPSConnectionShutdownError: Connection lost (error code is 100353)
EElSSLClientConnectionLostError: Connection lost (error code is 10058)

Then I get:

EElSocketError: Wrong socket state 0 in CanReceive (error code is 96258)
the previous 100353 error.

If I keep trying, a NullReferenceException is thrown somewhere inside SecureBlackbox.

Neither OnError or OnConnectionClose are triggered. I have to shutdown the emulator, restart it, and only then does the request go through properly (and not even always).

Then, if the first request after the initial 400 does go through, the previous entire 400 request is appended to the bottom of the TElRESTClient.ResponseText, after the json body of the second request. I don't see a way to flush the ResponseText after a request.

For example: telRESTClient.PostAsync(...) returns a 200, and telRESTClient.ResponseText is

{"somejsonfield":"somejson"}HTTP/1.1 400 Bad Request
Cache-control: no-cache="set-cookie"
Content-Type: application/json
Date: ...
Server: nginx
{"error_code" : 1232, "description" : "trigger that other flow"}

All in all the behaviour appears to be wildly unpredictable.

I also don't understand why I would be getting a 100353, seeing as I'm connecting over HTTP and the other flows work fine. The server is probably doing something weird (unfortunately this is an internal test server).

This is probably very difficult to diagnose for you guys since the server is unavailable, but perhaps one of you could point me in the right direction? What should I be investigating? Beyond that, what is the recommended way to recover from these types of errors?
Posted: 10/12/2015 09:46:58
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

If I keep trying, a NullReferenceException is thrown somewhere inside SecureBlackbox.

Could you please post exception stack trace here to check.
Posted: 10/12/2015 10:05:59
by OGAlex (Standard support level)
Joined: 06/08/2015
Posts: 13

at SBSocket.TElSocket.RTSend(Byte[] Data, Int32 Start, Int32 ToSend, Int32 Timeout)
at SBSocket.TElSocket.Send(Byte[] Data, Int32 Start, Int32 Len, Int32 Timeout, Int32& Sent)
at SBSimpleSSL.TElCustomSimpleSSLClient.DoSend(Object Sender, Byte[] Buffer)
at SBSSLClient.TElSSLClient.DoSend(Byte[] Buffer)
at SBSSLClient.TElSSLClient.SendData(Byte[] Buffer)
at SBSSLClient.TElSSLClient.SendData(Byte[] Buffer, Int32 StartIndex, Int32 Count)
at SBSimpleSSL.TElCustomSimpleSSLClient.SendData(Byte[] Buffer, Int32 StartIndex, Int32 Count)
at SBHTTPSClient.TElHTTPSClient.PerformExchange()

Note that they are caught. Then I can catch a EElHTTPSConnectionShutdownError: Connection lsot (error code is 100353).

But in the beginning these NullReferenceExceptions are not thrown.

Anyway, these types of errors only seem to happen in error flows. Happy flows tend to go well. Unfortunately I can't test the happy flow because the ResponseText is malformed and still contains the previous request.
Posted: 10/13/2015 04:41:35
by Vsevolod Ievgiienko (EldoS Corp.)

Thank for the details.

I was not able to reproduce malformed ResponseText. However you can use TElRESTClient.OutputStream.SetLength(0) to reset its state.

You can also post a code snippet or a compilable test case here that we can use to reproduce the problem locally.
Posted: 10/16/2015 04:30:19
by OGAlex (Standard support level)
Joined: 06/08/2015
Posts: 13

I have found and solved the issue. So just in case anyone else comes across a similar problem, here was my problem:

The issue was essentially a missing await keyword further up my code, resulting in an async GET to the TElRESTClient immediately after an async POST request, before it had been completed.

The reason I had trouble finding it was because my breakpoints were after the missing await, and the code leading to the GET was elsewhere, meaning I never saw the other thread executing the other request. My proxy also never showed more than one request being sent.

Sometimes this request would be a GET with the appropriate headers, and sometimes a POST with the appropriate headers but no body. Sometimes it would be the correct POST with body. As a result I got inconsistent errors every time and if it did go through, sometimes the response was mangled as well, with the correct response body to the POST and then the entire GET response right below it. A lot of the time an exception was thrown and I never got anything at all.

Lesson learned, be very thorough with asynchronous code. Hopefully this will help someone in the future.
Posted: 10/16/2015 04:34:05
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you very much for detailed description of the problem solution. It will be useful for other users.
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.



Topic viewed 1763 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!