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

Variable array with more than 'count' elements #60

Open
kasemir opened this issue Feb 12, 2019 · 3 comments
Open

Variable array with more than 'count' elements #60

kasemir opened this issue Feb 12, 2019 · 3 comments

Comments

@kasemir
Copy link

kasemir commented Feb 12, 2019

When creating an array PV with 'count' : 6, one can later call setParam with 0, 1, 2, .. 6 elements.
Reasonably recent Channel Access clients support such changing array sizes.

Turns out that pcaspy even allows calling setParam with more elements than originally specified by count, and some CA clients handle it, but the CA gateway does not.
Our PV Gateway Version 2.1.0 built with EPICS R3.14.12.6 crashed with symptoms of memory corruption each time we accessed such a PV that declared 'count': 1000 but then set the value to an array with 100000 elements. The last log message before each crash mentioned a value update with 100000 elements, but erroneously associated it with a different channel, again as a result of memory corruption.

While this is in part a bug in the gateway, the common agreement for the use of variable size arrays is that the 'count', which is for record-based IOCs configured via the waveform NELM field, sets the maximum array size, and value updates will then contain 0, 1, 2, .. elements up to that maximum element count. This allows clients to reserve a known amount of memory for storing received value updates.

Can pcaspy check the data passed to setParam, and in case of arrays at least warn, maybe even truncate or ignore array values with more than count elements?

@anacso17
Copy link

anacso17 commented Aug 4, 2023

Related issue: epics-extensions/ca-gateway#49.

@xiaoqiangwang
Copy link
Collaborator

I did not react on this issue because it is a good "feature" to provide variable length array PV. It is upon the application developer to respect the array size limit.

@kasemir
Copy link
Author

kasemir commented Aug 4, 2023

Well, yes, it's these days common to have 'array' classes that can simply change size, internally freeing/re-allocating memory as necessary.
For control system devices, however, it's often better to reserve the maximum required array memory once and then keep using that same memory to prevent memory fragmentation or delays from re-allocations. So the array size may change, but must stay within an upper limit.
In other words: "It is upon the application developer to configure the array size limit.", and pcaspy should then stay within that limit.

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

3 participants