Skip to content

Keep ADS symbol handles alive for the layout lifetime#11

Open
ewastewa wants to merge 1 commit into
b-robotized:rollingfrom
launchpad-build:fix-symbol-handle-lifecycle-upstream
Open

Keep ADS symbol handles alive for the layout lifetime#11
ewastewa wants to merge 1 commit into
b-robotized:rollingfrom
launchpad-build:fix-symbol-handle-lifecycle-upstream

Conversation

@ewastewa

@ewastewa ewastewa commented May 19, 2026

Copy link
Copy Markdown

Summary

  • Store the AdsHandle returned by GetHandle(symbolName) on ADSDataLayout so its destructor only runs when the layout is destroyed, not at the end of the configure statement.
  • Cache the dereferenced uint32_t alongside the owner for the sum-request headers.

Fixes #10.

GetHandle returns a std::unique_ptr with a ResourceDeleter that issues
SYM_RELEASEHND on destruction. Dereferencing the temporary and copying
only the uint32_t left every layout pointing at a released handle.
TwinCAT happens to keep handle slots live for top-level GVL and MAIN
symbols held by other clients, but releases struct- and array-member
handles immediately, so sum-reads against those returned garbage and
crashed the read worker.

Store the AdsHandle in std::optional alongside the cached uint32_t so
the release only fires when the layout is destroyed.
@mfabregat

Copy link
Copy Markdown

Hey @ewastewa, thanks for looking into this! Just wanted to point out that I submitted a PR for this exact fix a bit earlier over in #8. It looks like we took a very similar approach. Let's see what the maintainers think!

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 this pull request may close these issues.

Symbol handles released immediately on resolve; sum-reads of struct/array members crash the worker

2 participants