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

Remove blocking on container exit for every new exec created #1601

Merged
merged 1 commit into from
Dec 12, 2022

Conversation

kiashok
Copy link
Contributor

@kiashok kiashok commented Dec 9, 2022

Fixes the memory leak seen in the shim. Removes the creation of channel that waits on container exit for every new exec created.

Instead, a new function 'WaitChannel()' is added to the Container interface to expose the wait channel of a container. The caller of WaitChannel() can use the container's wait channel to decide if the container has exited or not rather than creating a new channel for every exec and blocking on container.Wait() call.

internal/hcs/system.go Outdated Show resolved Hide resolved
internal/gcs/container.go Outdated Show resolved Hide resolved
@@ -90,4 +90,7 @@ type Container interface {
Wait() error
// Modify sends a request to modify container resources
Modify(ctx context.Context, config interface{}) error

// WaitChannel returns the wait channel of the container
WaitChannel() <-chan struct{}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Done() <- chan struct{}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we are using waitBlock channel and waitError in the container structures, would WaitChannel() and WaitError() be better for readability?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am with Maksim on this, since Done mirrors how contexts do it and makes the convention match

internal/hcs/system.go Outdated Show resolved Hide resolved
@@ -291,6 +291,10 @@ func (computeSystem *System) waitBackground() {
oc.SetSpanStatus(span, err)
}

func (c *System) WaitChannel() <-chan struct{} {
return c.waitBlock
Copy link
Contributor

Choose a reason for hiding this comment

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

looking at the code we don't currently close c.closeCh anymore during Close()... I wonder what happened there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! Infact I do not see closeCh being used anywhere too. Discussion on that here - https://github.com/microsoft/hcsshim/pull/1601/files#r1044855223

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could cleanup and refactor in the later long term fix I guess

@kevpar
Copy link
Member

kevpar commented Dec 9, 2022

By the way, think this is fine to undraft.

Commit fixes the memory leak seen in the shim.
It removes creation of channel that waits on container exit
for every new exec. Instead, the container wait channel is exposed
through WaitChannel() function which callers can use to decide
if container has exited or not.

Signed-off-by: Kirtana Ashok <Kirtana.Ashok@microsoft.com>
@kevpar
Copy link
Member

kevpar commented Dec 9, 2022

By the way, was there a reason you merged main into this branch? Generally such updates are not needed as GitHub will handle that when it merges the PR. In the cast of merge conflicts, it's usually better practice to rebase instead of merging, as that produces a cleaner commit history.

@kiashok
Copy link
Contributor Author

kiashok commented Dec 9, 2022

By the way, was there a reason you merged main into this branch? Generally such updates are not needed as GitHub will handle that when it merges the PR. In the cast of merge conflicts, it's usually better practice to rebase instead of merging, as that produces a cleaner commit history.

No it was a mistake. I rebased and submitted to the PR soon after :)
Also, I'm editing the PR title and description to be a little more descriptive. Will undraft soon after that.

@kiashok kiashok changed the title Draft: Remove blocking wait for every exec created Remove blocking on container exit for every new exec created Dec 9, 2022
@kiashok kiashok marked this pull request as ready for review December 9, 2022 23:20
@kiashok kiashok requested a review from a team as a code owner December 9, 2022 23:20
Copy link
Member

@kevpar kevpar left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@helsaawy helsaawy left a comment

Choose a reason for hiding this comment

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

minor comment nit, lgtm overall

internal/gcs/container.go Show resolved Hide resolved
@kiashok kiashok merged commit 0b8319a into microsoft:main Dec 12, 2022
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.

None yet

4 participants