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

Memory leak on backup restore with xquery triggers #5459

Closed
line-o opened this issue Sep 30, 2024 · 4 comments
Closed

Memory leak on backup restore with xquery triggers #5459

line-o opened this issue Sep 30, 2024 · 4 comments

Comments

@line-o
Copy link
Member

line-o commented Sep 30, 2024

Describe the bug

I was able to reproduce the memory leak using the original dataset provided by @dariok. With enough resources, about 10 GB of RAM, the process did finish successfully. After restoring the entire dataset of 35 GB, containing 26874 XML files (including .html, .xsl, .svg), almost 5 GB of RAM retained.

Screenshot 2023-07-04 at 14 24 36

There is ~59000 instances of TriggerStatePerThread$TriggerState. Since I can see that there is two instances for each restored item that is ~29500 CREATE_DOCUMENT triggers - one for BEFORE and for the AFTER phase.

Screenshot 2023-07-05 at 11 32 00

I was then wondering whether I was missing +3000 documents until I discovered that CREATE_COLLECTION was also invoked:

Screenshot 2023-07-05 at 12 08 21 The original `collection.xconf` defines an update trigger as such: ``` ```

With the collection.xconf as it is in the issue description (without any triggers configured) the outcome was very different. RAM usage stayed within reasonable bounds (<2 GB) and all memory was freed afterwards (see screenshot).

Screenshot 2023-07-05 at 09 26 17

My analysis indicates that TriggerStates are held in memory indefinitely and are the cause of the leak. This is especially interesting as the events that were triggered are not the ones that are defined and thus one would not expect them to be fired at all.

References

refs #4890
refs #5295

Expected behavior

XQueryTriggerStates to be removed from memory once the trigger is done.

To Reproduce

If the above isn't working, please tell us the exact steps you took when you encountered the problem:

full-backup-restore-with-triggers.zip

  1. start a clean instance of exist-db v6.2.0 with a profiler attached
  2. restore the backup in the attached zip
  3. the backup finishes
  4. in the Profiler you should be able to find XqueryTriggerState instances that retain in memory

Screenshots

see above

Context

  • Build: eXist-6.2.0
  • Java: 1.8.0_352
  • OS: Mac OS X 14.5

Additional context

  • How is eXist-db installed? built from source
  • Any custom changes in e.g. conf.xml? none
@dizzzz
Copy link
Member

dizzzz commented Oct 1, 2024

images are not visible?
image

@adamretter
Copy link
Contributor

adamretter commented Oct 8, 2024

images are not visible?

@line-o Could we get an update please?

@line-o
Copy link
Member Author

line-o commented Oct 8, 2024

@adamretter Are you waiting for the screenshots? They are the same ones as in the other issue. I was expecting your PR, you were so eager to publish.
I really did not expect these to be important.

@adamretter
Copy link
Contributor

adamretter commented Oct 8, 2024

They are the same ones as in the other issue

@line-o Good to hear - but we had no idea that was the case as you hadn't replied! I have now fixed the links to the images for you so that the issue makes more sense (cc @dizzzz).

adamretter pushed a commit to evolvedbinary/exist that referenced this issue Oct 8, 2024
XQuery trigger not found is acceptable behaviour (logs a debug message only, could get very chatty logs otherwise).
BUT the exit path from the exception fails to tidy up the per-thread trigger state. This has been observed to leak memory; the per-thread doesn’t get cleaned up until the thread is deleted, and the trigger cyclic-check stack just builds up.

So we clean up the trigger state when a trigger is not found.

Closes eXist-db#5459
adamretter pushed a commit to evolvedbinary/exist that referenced this issue Oct 8, 2024
We may leak trigger states to thread local which can potentially occur when
the specified XQueryTrigger library module is not available in the database

Closes eXist-db#5459
@adamretter adamretter changed the title [BUG] memory leak on backup restore with xquery triggers Memory leak on backup restore with xquery triggers Oct 8, 2024
adamretter pushed a commit to evolvedbinary/exist that referenced this issue Oct 8, 2024
XQuery trigger not found is acceptable behaviour (logs a debug message only, could get very chatty logs otherwise).
BUT the exit path from the exception fails to tidy up the per-thread trigger state. This has been observed to leak memory; the per-thread doesn’t get cleaned up until the thread is deleted, and the trigger cyclic-check stack just builds up.

So we clean up the trigger state when a trigger is not found.

Closes eXist-db#5459
adamretter pushed a commit to evolvedbinary/exist that referenced this issue Oct 8, 2024
We may leak trigger states to thread local which can potentially occur when
the specified XQueryTrigger library module is not available in the database

Closes eXist-db#5459
adamretter pushed a commit to evolvedbinary/exist that referenced this issue Oct 8, 2024
XQuery trigger not found is acceptable behaviour (logs a debug message only, could get very chatty logs otherwise).
BUT the exit path from the exception fails to tidy up the per-thread trigger state. This has been observed to leak memory; the per-thread doesn’t get cleaned up until the thread is deleted, and the trigger cyclic-check stack just builds up.

So we clean up the trigger state when a trigger is not found.

Closes eXist-db#5459
adamretter pushed a commit to evolvedbinary/exist that referenced this issue Oct 8, 2024
We may leak trigger states to thread local which can potentially occur when
the specified XQueryTrigger library module is not available in the database

Closes eXist-db#5459
adamretter pushed a commit to evolvedbinary/exist that referenced this issue Oct 8, 2024
We may leak trigger states to thread local which can potentially occur when
the specified XQueryTrigger library module is not available in the database

Closes eXist-db#5459
adamretter pushed a commit to evolvedbinary/exist that referenced this issue Oct 10, 2024
XQuery trigger not found is acceptable behaviour (logs a debug message only, could get very chatty logs otherwise).
BUT the exit path from the exception fails to tidy up the per-thread trigger state. This has been observed to leak memory; the per-thread doesn’t get cleaned up until the thread is deleted, and the trigger cyclic-check stack just builds up.

So we clean up the trigger state when a trigger is not found.

Closes eXist-db#5459
adamretter pushed a commit to evolvedbinary/exist that referenced this issue Oct 10, 2024
We may leak trigger states to thread local which can potentially occur when
the specified XQueryTrigger library module is not available in the database

Closes eXist-db#5459
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