EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Exception in other thread when calling TELSimpleSSLClient.Open

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#16645
Posted: 06/13/2011 10:08:57
by John Daintree (Priority Standard support level)
Joined: 10/18/2010
Posts: 20

Hello All,

I'm trying to connect a ELSimpleSSLClient socket to a host/port combination in a Silverlight 4 application. If the connection is refused by the host I get a System.Net.Sockets.SocketException "No connection could be made because the target machine actively refused it.". However this exception is not raised on the thread that called Open, and so I have no way of catching it.

Is there a way of getting the exception on the thread that calls Open()?

Also, Can I drive the ELSimpleSSLClient in asynchronous mode? (like the underlying Silverlight Socket class, ConnectAsync, ReadAsync etc), that'd make my life much easier.(I'm trying to migrate from SL sockets to blackbox sockets).

Thanks,
John
#16647
Posted: 06/13/2011 10:26:05
by Eugene Mayevski (EldoS Corp.)

Quote
John Daintree wrote:
Is there a way of getting the exception on the thread that calls Open()?


Silverlight reports status updates in a different thread and this is where the exception goes. You should get SecureBlackbox exception in the thread that called Open. Do you get one? If now, then how does the component behave?

Quote
John Daintree wrote:
Also, Can I drive the ELSimpleSSLClient in asynchronous mode? (like the underlying Silverlight Socket class, ConnectAsync, ReadAsync etc), that'd make my life much easier.(I'm trying to migrate from SL sockets to blackbox sockets).


No, this is purely synchronous component. If you need asynchronous component, you can use TElSecureClient (this is a client-side SSL/TLS engine which doesn't use sockets) and combine it with sockets of your choice or any other transport (yes, SSL/TLS doesn't care if you use sockets or pigeon mail).


Sincerely yours
Eugene Mayevski
#16649
Posted: 06/13/2011 10:41:14
by John Daintree (Priority Standard support level)
Joined: 10/18/2010
Posts: 20

Hi Eugene,

No, I don't get an exception at all in the thread that called Open(). The full stack in the failing thread is like this:
SecureBlackbox!SBSocket.TElSocket.SLProcessConnect(System.Net.Sockets.SocketAsyncEventArgs e = {System.Net.Sockets.SocketAsyncEventArgs}) + 0x82 bytes
SecureBlackbox!SBSocket.TElSocket.SocketArgs_Completed(object Sender = {System.Net.Sockets.Socket}, System.Net.Sockets.SocketAsyncEventArgs e = {System.Net.Sockets.SocketAsyncEventArgs}) + 0x76 bytes
System.Net.dll!System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs e) + 0x16 bytes
System.Net.dll!System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(System.Exception exception, int bytesTransferred, System.Net.Sockets.SocketFlags flags) + 0x69 bytes
System.Net.dll!System.Net.Sockets.Socket.ConnectAsyncCallback(object sender, System.Net.Sockets.SocketAsyncEventArgs args) + 0xa7 bytes
System.Net.dll!System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs e) + 0x16 bytes
System.Net.dll!System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(System.Net.Sockets.SocketError socketError, int bytesTransferred, System.Net.Sockets.SocketFlags flags) + 0x57 bytes
System.Net.dll!System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* nativeOverlapped) + 0xa6 bytes
mscorlib.dll!System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP) + 0x8e bytes
[Native to Managed Transition]
[Appdomain Transition]
[Native to Managed Transition]



Looking at the IL for the SLProcessConnect function I can see that it does throw the SocketException that I am seeing.

The thread that called Open() is sitting here: (and I have a try...catch around the call to Open().

[In a sleep, wait, or join]
mscorlib.dll!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle waitableSafeHandle, long millisecondsTimeout, bool hasThreadAffinity, bool exitContext) + 0x24 bytes
mscorlib.dll!System.Threading.WaitHandle.WaitOne(long timeout, bool exitContext) + 0x22 bytes
mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext) + 0x20 bytes
mscorlib.dll!System.Threading.WaitHandle.WaitOne() + 0x10 bytes
SecureBlackbox!SBSocket.TElSocket.AsyncConnect(int Timeout = 0) + 0x384 bytes
SecureBlackbox!SBSocket.TElSocket.Connect(int Timeout = 0) + 0x8d bytes
SecureBlackbox.SSLClient!SBSimpleSSL.TElCustomSimpleSSLClient.Open() + 0x560 bytes
> RIDE!RIDE.SSL.SSocket.Connect() Line 320 + 0x10 bytes C#
RIDE!RIDE.SSL.SSocket.ConnectAsync(System.Net.Sockets.SocketAsyncEventArgs a = {System.Net.Sockets.SocketAsyncEventArgs}) Line 414 + 0x9 bytes C#
RIDE!RIDE.Monitor.DoMonitorProcesses(object thread_args = {string[1]}) Line 98 + 0xd bytes C#
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0xa5 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0x97 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x2a bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart(object obj) + 0x4b bytes
[Native to Managed Transition]
[Appdomain Transition]
[Native to Managed Transition]
#16679
Posted: 06/16/2011 08:14:48
by John Daintree (Priority Standard support level)
Joined: 10/18/2010
Posts: 20

Hi Eugene,

I also have a similar problem if a socket is closed by the other end of the connection when I'm sitting on ReceiveData().

try
{
SecureClient.ReceiveData(ref Buffer, ref c, all);
Array.Copy(Buffer, a.Buffer, c);
a.BytesTransferred = c;
}
catch (Exception e)
{
a.BytesTransferred = 0;
}


The catch block isn't called, and I get an untrappable exception in *your* thread that's called SBSocket.TElSocket.SLProcessReceive.

Thanks,
John
#16680
Posted: 06/16/2011 08:40:55
by Eugene Mayevski (EldoS Corp.)

1) This is *not* "our" thread. This is a thread created by Silverlight to call asynchronous callback.

2) Our code follows the guidelines and samples presented in MSDN on handling completion of operations, including reporting errors by throwing the exception (see C# sample in the MSDN for details). I.e. our code throws an instance of SocketException in the asynchronous callback handler, if there was an error.

I guess you have enabled "break on exceptions" in IDE and what you see is caused by that setting. If you disable breaking on exception (or at least do this for SocketException class), code execution should continue normally. We have at least several users who use SecureBlackbox and TElSimpleSSLClient class (or it's descendants) in Silverlight and it works for them just fine. So I think your problem is local and caused by your settings rather than by some mistake in our code.


Sincerely yours
Eugene Mayevski
#16681
Posted: 06/16/2011 09:14:37
by John Daintree (Priority Standard support level)
Joined: 10/18/2010
Posts: 20

Hi Eugene,

Sorry, I wasn't trying to suggest that it was a mistake in the code, I'm just trying to figure out where the problem is. I'll read the MSDN article, and come back to you later.

/john
#16685
Posted: 06/17/2011 05:43:02
by John Daintree (Priority Standard support level)
Joined: 10/18/2010
Posts: 20

Hello Eugene,

SecureBlackbox is working out pretty well for us so far, it certainly does work with Silverlight, but I am sort of stuck on this exception issue.

I think there is a difference here between the .Net 4 and Silverlight 4 error handling. I've written the following simple example:

Code
private void connect_Click(object sender, EventArgs e)
        {
            SBSimpleSSL.TElSimpleSSLClient SecureClient;  

            SecureClient = new SBSimpleSSL.TElSimpleSSLClient();

            SecureClient.Address = "127.0.0.1";
            SecureClient.Port = 4502;
       SecureClient.SocketTimeoout=10000;
  
            try
            {
                SecureClient.Open();
                Status("Connected");
            }
            catch (Exception x)
            {
            Status(x.Message);
            }

            Status("all done");
        }


I have a socket open on localhost that provides a client access policy for silverlight. There is no socket listening on 4502.

Both .Net 4 and Silverlight generate an exception "No connection could be made because the target machine actively refused it". In the .Net case this exception is caught by my exception handler and the message reports socket error WSAECONNREFUSED. However, in the Silverlight case my exception handler does not get this exception. Instead the Application_UnhandledExceptionHandler is called, if I set e.Handled=true the SecureClient.Open call eventually throws an exception (WSAETIMEDOUT). If I don't set e.Handled, or if I don't handle Application_UnhandledExceptionHandler then the application aborts with a fatal error.

Can I configure the SecureClient so that the Silverlight case works the same way as the .Net case? It doesn't seem right that I have to wait for the timeout, and it also doesn't seem right to have to handle this in Application_UnhandledExceptionHandler.

The behaviour is the same if I run it under the debugger, or I run it without debugging.

I've looked (and built) the MDSN sample you pointed be at, and it also generates an untrappable exception (and so kills the application), so I'm not convinced that the sample is very good.

Thanks again,
John.
#16686
Posted: 06/17/2011 06:11:44
by Eugene Mayevski (EldoS Corp.)

Thank you for detailed description of the problem - now I understand what's going on.

Silverlight has only asynchronous methods which report their status via the asynchronous callback, executed in context of secondary thread (exactly what you see now). We followed documentation (which I referred to) when implementing the callback handler. Now it sounds like the documentation is either incorrect or misleading (or both).

To answer your question, it's not possible to make Silverlight sockets behave like .NET's one because they are severely crippled. I guess we will need to re-work error handling in Silverlight-specific code. This can be done, but not immediately (as it would require some testing etc. ). I believe we will solve this issue in one of upcoming builds.


Sincerely yours
Eugene Mayevski
#16688
Posted: 06/17/2011 06:26:57
by John Daintree (Priority Standard support level)
Joined: 10/18/2010
Posts: 20

Thanks Eugene,

We're almost ready to commit to buying a license for BlackBox. I understand that it comes with source code. Would it be possible (both technically and from a licensing point of view), for me to change the code, rebuild blackbox, and ship the new binaries.

/john
#16689
Posted: 06/17/2011 06:48:46
by Eugene Mayevski (EldoS Corp.)

The code is written in Pascal (compiled with Delphi Prism). If you feel comfortable with this, then yes, you can build your own assemblies and ship your application with those custom assemblies. You can re-arrange the code between assemblies (eg. to make them smaller) etc. .


Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.

Reply

Statistics

Topic viewed 5195 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!