Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint Discovery fails calling SelectEndpoint #3027

Open
1 of 5 tasks
benjsherman opened this issue Mar 4, 2025 · 2 comments
Open
1 of 5 tasks

Endpoint Discovery fails calling SelectEndpoint #3027

benjsherman opened this issue Mar 4, 2025 · 2 comments

Comments

@benjsherman
Copy link

Type of issue

  • Bug
  • Enhancement
  • Compliance
  • Question
  • Help wanted

Current Behavior

In UAClient.cs on line 200, this fails when trying to connect to the same OPCUA server in succession.
Here is the stack trace:

Opc.Ua.ServiceResultException: Error establishing a connection: BadNotConnected
   at Opc.Ua.Bindings.ChannelAsyncOperation`1.End(Int32 timeout, Boolean throwOnError)
   at Opc.Ua.Bindings.UaSCUaBinaryClientChannel.EndSendRequest(IAsyncResult result)
   at Opc.Ua.Bindings.UaSCUaBinaryTransportChannel.EndSendRequest(IAsyncResult result)
   at Opc.Ua.Bindings.UaSCUaBinaryTransportChannel.SendRequest(IServiceRequest request)
   at Opc.Ua.DiscoveryClient.GetEndpoints(RequestHeader requestHeader, String endpointUrl, StringCollection localeIds, StringCollection profileUris, EndpointDescriptionCollection& endpoints)
   at Opc.Ua.DiscoveryClient.GetEndpoints(StringCollection profileUris)
   at Opc.Ua.Client.CoreClientUtils.SelectEndpoint(ApplicationConfiguration application, String discoveryUrl, Boolean useSecurity, Int32 discoverTimeout)
   at Opc.Ua.Client.CoreClientUtils.SelectEndpoint(ApplicationConfiguration application, String discoveryUrl, Boolean useSecurity)

Expected Behavior

I expect to be able create as connections as my OPCUA server will allow without any errors. I don't expect it to error during endpoint discovery.

Steps To Reproduce

Replicate by setting up two unit tests each connecting to the same OPCUA server, the first conneciton will succeed, the second connection will fail. If run separately both will succeed.

Also interesting is adding a Thread.Sleep of one second in the Dispose method prevents this error

Environment

- OS: Windows 11
- Environment:
- Runtime:x64
- Nuget Version: 1.5.375.457
- Component:
- Server:
- Client: x

Anything else?

No response

@romanett
Copy link
Contributor

romanett commented Mar 5, 2025

@benjsherman Thank you for reporting a potential bug. Please provide the exact sequence of function calls to the UAClient.cs or even better a test project.

@benjsherman
Copy link
Author

I've attached a project with unit tests for replication of my issue:

Code.zip

Solution file is under Code/OPCUACLient/OPCUAClient.sln

Failing function call is documented in OpcDataService.cs Line 129

OpcFoundationTest.cs has two test that when ran in batch, one will fail.
There are two lines to sleep after doing the OPCUA read that when uncommented, permits both tests to pass when run in batch.

You'll need a valid OPCUA server to connect to and this test scenario was against an un-signed, un-secured, no credential OPCUA server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants