nauful / LibUA

Open-source OPC UA client and server library
Apache License 2.0
262 stars 94 forks source link

Semaphore race condition with later client Connect calls #107

Closed wckivX closed 2 years ago

wckivX commented 2 years ago

The Connect method of Client.cs creates a new Semaphore (cs) each time it is called. It should only create a new Semaphore if cs is null.

Existing Client.cs code:

cs = new Semaphore(1, 1);

Proposed change:

if (null == cs) { cs = new Semaphore(1, 1); }

If a second call to Connect is made, concurrent method calls using cs for synchronization can have their cs Semaphore changed to a new instance. This probably only triggers on poorly written code.

nauful commented 2 years ago

A few other variables would also need to be cleaned. Cleaner fix: https://github.com/nauful/LibUA/commit/20e63854a01b98d968af69a72465a6833b316b2f