View Issue Details

IDProjectCategoryView StatusLast Update
0002878UAImplementation Bugpublic2015-06-18 13:52
ReporterZbynek Zahradnik Assigned ToNathan Pocock 
PriorityhighSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
PlatformWindows 
Summary0002878: .NET client stack - infinite hang in CreateSession
Description

Observed with .NET stack 1.02.334.6.

Opc.Ua.Client.Session.Open, when called with m_endpoint.Description.SecurityPolicyUri == SecurityPolicies.None, and m_endpoint.EndpointUrl which represents an unknown host, hangs indefinitely.

The actual issue can be wider - it may affect more methods, and almost certainly happens with other errors (not just unknown host) as well.

Steps To Reproduce

Call Opc.Ua.Client.Session.Open with the values indicated in Description. It will first try to call CreateSession with a NULL client certificate.

Because of the unknown host, this throws a SocketException somewhere in the stack. This is caught in Opc.Ua.Client.Session.Open and traced as "Create session failed with client certificate NULL. ". The code then proceeds to a second CreateSession call, now with the actual client certificate. It hangs indefinitely in there.

I can guess that the issue has to with either 1) the fact that a SocketException leaves the session or the channel are left in an incorrect state, or 2) in case of errors like this (as opposed to service-level errors), the second CreateSession should not be made at all, or 3) both.

Additional Information

Call stack of the thread that is forever blocked:

mscorlib.dll!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle waitableSafeHandle, long millisecondsTimeout,

bool hasThreadAffinity, bool exitContext) Line 243 + 0x14 bytes C#
mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext) Line 194 + 0x23 bytes C#

Opc.Ua.Core.dll!Opc.Ua.Bindings.TcpAsyncOperation<int>.End(int timeout) Line 178 + 0x19 bytes C#
Opc.Ua.Core.dll!Opc.Ua.Bindings.TcpClientChannel.EndSendRequest(System.IAsyncResult result) Line 308 + 0xf bytes C#
Opc.Ua.Core.dll!Opc.Ua.Bindings.TcpTransportChannel.EndSendRequest(System.IAsyncResult result) Line 341 + 0xd bytes C#
Opc.Ua.Core.dll!Opc.Ua.Bindings.TcpTransportChannel.SendRequest(Opc.Ua.IServiceRequest request) Line 291 + 0xb bytes C#
Opc.Ua.Core.dll!Opc.Ua.SessionClient.CreateSession(Opc.Ua.RequestHeader requestHeader, Opc.Ua.ApplicationDescription clientDescription,

string serverUri, string endpointUrl, string sessionName, byte[] clientNonce, byte[] clientCertificate, double requestedSessionTimeout, uint

maxResponseMessageSize, out Opc.Ua.NodeId sessionId, out Opc.Ua.NodeId authenticationToken, out double revisedSessionTimeout, out byte[]

serverNonce, out byte[] serverCertificate, out Opc.Ua.EndpointDescriptionCollection serverEndpoints, out Opc.Ua.SignedSoftwareCertificateCollection

serverSoftwareCertificates, out Opc.Ua.SignatureData serverSignature, out uint maxRequestMessageSize) Line 108 + 0x1d bytes C#
...
Opc.Ua.Client.dll!Opc.Ua.Client.Session.Open(string sessionName, uint sessionTimeout, Opc.Ua.IUserIdentity identity,

System.Collections.Generic.IList<string> preferredLocales) Line 2039 + 0x154 bytes C#

TagsNo tags attached.
Fix Due Date

Activities

Alin Moldovean

2015-06-18 13:52

reporter   ~0006151

Fixed bug. When connecting to an unknown host an exception is thrown in the Socket.BeginConnect method called by TcpClientChannel.BeginConnect, resulting in an improper "connecting" state for the socket (no cleanup will be performed).
A subsequent connect would not try to (re)connect the socket, as the "firstCall" variable would be false (the m_queuedOperations was not emptied by the first SessionConnect call).

Fix: The Socket.BeginConnect in TcpClientChannel.BeginConnect method has been surrounded by a try-catch block to shutdown the socket in case of an System.Net.Sockets.SocketException.

Issue History

Date Modified Username Field Change
2014-11-05 12:49 Zbynek Zahradnik New Issue
2015-06-18 13:52 Alin Moldovean Note Added: 0006151
2015-06-18 13:52 Alin Moldovean Status new => resolved
2015-06-18 13:52 Alin Moldovean Resolution open => fixed
2015-06-18 13:52 Alin Moldovean Assigned To => Nathan Pocock