Skip to content

Clear the record cache between unit test cases - #61

Merged
tynanford merged 1 commit into
epics-modules:masterfrom
pheest:no_cache_records
Oct 26, 2026
Merged

tynanford merged 1 commit into
epics-modules:masterfrom
pheest:no_cache_records

Conversation

@pheest

@pheest pheest commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

See #60

Re-used record instances stored in _rec_cache do not work, as they are invalided by the record instance destructor.

This usage causes segmentation faults and/or unpredictable behaviour as highlighted in #60

Added tests for use of array record types, although the noted issue has turned out to be generic to all types.

@pheest pheest self-assigned this Sep 21, 2026
@mdavidsaver

Copy link
Copy Markdown
Collaborator

Re-used record instances stored in _rec_cache do not work, as they are invalided by the record instance destructor.

To me this describes a premature Py_DECREF leading to a use-after-free situation.

I don't see much performance cost to eliminating _rec_cache. Mainly some extra dbFindRecord(). However, I suspect this would only mask one symptom of some unknown ref. counting bug.

@tynanford tynanford changed the title Removed use of the _rec_cache variable in db.py as cached and then re… Clear the record cache between unit test cases Oct 26, 2026
Applied fix for access violation / seg fault within the test harness.
testdbCleanup() frees every record at the end of each IOCHelper test
case, but devsup.db._rec_cache keeps the Record objects, whose pointers
then dangle. A later test case calling getRecord() on the same name got
the stale object, causing segfaults.

Also add tests which reuse record names to cover this scenario
@tynanford

Copy link
Copy Markdown
Collaborator

We found that this issue only occurs in the unit tests and not in the running IOC. So the record cache is added back but the unit test harness is updated to clear the cache between tests. Peter also added tests that reuse the record name to test the fix

@tynanford

Copy link
Copy Markdown
Collaborator

Also it looks like the CI failures are separate issue we can fix with another PR

@tynanford
tynanford merged commit f8332ec into epics-modules:master Oct 26, 2026
16 of 20 checks passed
@pheest
pheest deleted the no_cache_records branch October 28, 2026 08:34
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.

3 participants