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

fix(cwl): Dispose event listeners when command exits #6095

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

keeganirby
Copy link

@keeganirby keeganirby commented Nov 22, 2024

Problem

TailLogGroup command is not being fully cleaned up properly. The event listeners for:

  • showing the StatusBar item
  • closing a session when exiting its editors

are not being disposed of. As users stop sessions, these listeners remain active whilst doing no meaningful work. This is effectively a memory leak.

Additionally during testing, I noticed that we are adding a session to the LiveTailRegistry before the session is actually started. This could cause an issue where a session stream isn't successfully created, but the session is still registered.

Solution

  • Create an array of disposables and dispose of them as we exit the TailLogGroup command
  • Only register a session after startLiveTail returns

Because now we dispose of the "tab close" listener when tailLogGroup exits, changes are needed in the unit tests to keep the mock response stream "open" as the test executes. This keeps tailLogGroup from returning/disposing while we perform test assertions and close the editors.


License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@keeganirby keeganirby requested a review from a team as a code owner November 22, 2024 21:39
@keeganirby keeganirby changed the title Dispose event listeners when command exits fix(cwl): Dispose event listeners when command exits Nov 22, 2024
Copy link

  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

groupName: testLogGroup,
regionName: testRegion,
})
await new Promise((r) => setTimeout(r, 500))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of doing a sleep can we do a waitUntil something happens?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, TailLogGroup doesn't expose anything that we can wait on that tells us that we have done the work required to do our test assertions.

We could possibly emit an event each time the command processes a new Stream frame. Then in the test we would waitUntil the event is emitted X times.

So far the actual feature hasn't required that, but I can look into adding that for test purposes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was able to use waitUntil by waiting on the LiveTailRegistry to see when there's a session in there (signals session started).

Then we can wait until the content in the document matches the expected. This is does both: validating the content of the doc, and waiting until the stream is fully processed.

@keeganirby
Copy link
Author

Accident closed while trying to update my local feature branch against the remote branch.

@keeganirby keeganirby reopened this Nov 26, 2024
let clock: FakeTimers.InstalledClock

before(function () {
clock = installFakeClock()
Copy link
Author

@keeganirby keeganirby Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using fake clocks is screwing with the waitUntil() calls. Inspecting the test that uses the clock: the assertions made against the fake clock is a functionality of LiveTailSession.closeSession(), and not TailLogGroup. If we want to assert that the timer is disposed of, it should be done in those unit tests, and not here.

Removing the clock.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed: #6110

@jpinkney-aws jpinkney-aws merged commit 06b390d into aws:feature/cwltail Nov 26, 2024
25 of 26 checks passed
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.

2 participants