nrkno / sofie-core

Sofie Core: A Part of the Sofie TV Studio Automation System
https://github.com/nrkno/Sofie-TV-automation/
MIT License
125 stars 38 forks source link

fix: stop old observers when re-creating nested observers SOFIE-3016 #1167

Closed Julusian closed 6 months ago

Julusian commented 6 months ago

About the Contributor

This pull request is posted on behalf of the NRK.

Type of Contribution

This is a: Bug fix

Current Behavior

We have identified that there is a memory leak in Sofie that gets worse each day.

Through some local testing, I identified a scenario where this happens and verified it with some debug logging. To reproduce:

  1. Add two or more rundowns into a playlist
  2. In the ui, manually remove one of those rundowns from the playlist. At this point, the debug logging will show that the observers have been re-created to just consider the rundowns which remain in the playlist
  3. In the ui, manually delete the rundown which is no longer in the playlist The debug logging will show that the publication was invalidated from deleting of this rundown.

The issue was that whenever we re-created this RundownsObserver, we would not call the cleanup function before re-initialising the child observers. This would result in them being leaked, preserving some memory and continuing their watching of the mongo and in-memory collections.

Other Information

Status

codecov[bot] commented 6 months ago

Codecov Report

Attention: Patch coverage is 80.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 59.08%. Comparing base (a04c695) to head (fe433be). Report is 19 commits behind head on release49.

Files Patch % Lines
...ons/pieceContentStatusUI/rundownContentObserver.ts 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## release49 #1167 +/- ## ========================================== Coverage 59.07% 59.08% ========================================== Files 473 473 Lines 71613 71634 +21 Branches 3724 3725 +1 ========================================== + Hits 42308 42323 +15 - Misses 29258 29265 +7 + Partials 47 46 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.