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

Failed mutex assertion with TCP_sendWithConnection() in 1.4 #6455

Closed
3 of 7 tasks
sgoll opened this issue May 3, 2024 · 1 comment · Fixed by #6488
Closed
3 of 7 tasks

Failed mutex assertion with TCP_sendWithConnection() in 1.4 #6455

sgoll opened this issue May 3, 2024 · 1 comment · Fixed by #6488

Comments

@sgoll
Copy link
Contributor

sgoll commented May 3, 2024

Description

Background Information / Reproduction Steps

When issuing concurrent calls to both UA_Client_run_iterate() and __UA_Client_AsyncService(), there is a race condition where the following assertion at the beginning of TCP_sendWithConnection() may fail:

/* Don't have a lock and don't take a lock. As the connectionId is the fd,
* no need to to a lookup and access internal data strucures. */
UA_LOCK_ASSERT(&((UA_EventLoopPOSIX*)cm->eventSource.eventLoop)->elMutex, 0);

This manifests itself in the following error at runtime. Both functions are marked UA_THREADSAFE:

Assertion failed: (lock->mutexCounter == num), function UA_LOCK_ASSERT, file config.h, line 426.

My guess is that this happens when __UA_Client_AsyncService() tries to send out the request while another thread holds the mutex lock while iterating the event loop from within UA_Client_run_iterate(). Looking at the log output preceding the failed assertion, it seems that at the same time as sending the request, the response to another request arrives at the client:

Iterate the EventLoop
Process delayed callbacks
TCP 5        | SC 262911     | Sending request with RequestId 17 of type BrowseRequest
Processing event 1 on fd 5
TCP 5        | Activity on the socket
TCP 5        | SC 262911     | Send from a symmetric message buffer of length 131072 a message of header+payload length of 9153
TCP 5        | Allocate receive buffer
TCP 5        | SC 262911     | Send from a symmetric message buffer of length 131072 a message of length 9153
Assertion failed: (lock->mutexCounter == num), function UA_LOCK_ASSERT, file config.h, line 426.

Used CMake options:

cmake ..

Checklist

Please provide the following information:

  • open62541 Version (release number or git tag): v1.4.0
  • Other OPC UA SDKs used (client or server):
  • Operating system: macOS
  • Logs (with UA_LOGLEVEL set as low as necessary) attached
  • Wireshark network dump attached
  • Self-contained code example attached
  • Critical issue
uklotzde added a commit to HMIProject/open62541 that referenced this issue May 8, 2024
## Description

This PR is a follow-up to #102 and adds an example that triggers the
assertion error in open62541/open62541#6455.

A typical run looks like this:

```
> cargo run --example async_concurrent
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/examples/async_concurrent`
Children: 26
Children: 26
Children: 26
Assertion failed: (lock->mutexCounter == num), function UA_LOCK_ASSERT, file config.h, line 422.
fish: Job 1, 'cargo run --example async_read_…' terminated by signal SIGABRT (Abort)
```

---------

Co-authored-by: Uwe Klotz <uwe.klotz@gmail.com>
@sgoll
Copy link
Contributor Author

sgoll commented May 15, 2024

@jpfr I'd like to contribute a PR but I'm unsure whether it's sufficient to just remove the assertion (because it describes an invalid assumption) or to actually take the lock instead.

sgoll added a commit to HMIProject/open62541 that referenced this issue May 17, 2024
## Description

This PR temporarily adds back a mutex to serialize library calls in
`AsyncClient`. The entire commit should be reverted and the mutex
removed again when the issue described in
open62541/open62541#6455 has been resolved.
@jpfr jpfr closed this as completed Jun 3, 2024
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

Successfully merging a pull request may close this issue.

2 participants