Skip to content

Conversation

@keeganirby
Copy link
Contributor

@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
@github-actions
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
Contributor 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
Contributor 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
Contributor 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
Contributor 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
Contributor 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
jpinkney-aws pushed a commit that referenced this pull request Dec 4, 2024
…ject. (#6110)

## Problem
The `LiveTailSession` object's start/stop methods aren't directly under
test. TailLogGroup tests are mocking their behavior. TailLogGroup
command tests are more focused on managing the session registry,
opening/writing to the document, and the close tab behaviors.

## Solution
Write a test that's scoped to creating a `session` and calling start and
stop on it. Assert that timers are handled/disposed of properly, and
that the session response stream is returned.

Addresses [this
comment](#6095 (comment)).

---

<!--- REMINDER: Ensure that your PR meets the guidelines in
CONTRIBUTING.md -->

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

---------

Co-authored-by: Keegan Irby <[email protected]>
karanA-aws pushed a commit to karanA-aws/aws-toolkit-vscode that referenced this pull request Jan 17, 2025
## 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.
karanA-aws pushed a commit to karanA-aws/aws-toolkit-vscode that referenced this pull request Jan 17, 2025
…ject. (aws#6110)

## Problem
The `LiveTailSession` object's start/stop methods aren't directly under
test. TailLogGroup tests are mocking their behavior. TailLogGroup
command tests are more focused on managing the session registry,
opening/writing to the document, and the close tab behaviors.

## Solution
Write a test that's scoped to creating a `session` and calling start and
stop on it. Assert that timers are handled/disposed of properly, and
that the session response stream is returned.

Addresses [this
comment](aws#6095 (comment)).

---

<!--- REMINDER: Ensure that your PR meets the guidelines in
CONTRIBUTING.md -->

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

---------

Co-authored-by: Keegan Irby <[email protected]>
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