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 Windows layer leak when write fails#36728

Merged
merged 1 commit into from
Apr 5, 2018

Conversation

darstahl
Copy link
Contributor

@darstahl darstahl commented Mar 29, 2018

Signed-off-by: Darren Stahl darst@microsoft.com

fixes #31253

- What I did

Fixed a leaked handle that was causing layer deletion to fail when the write of the tar contents failed. This was preventing layer deletion, resulting in a lot of un-removable layers left on disk.

- How I did it

Fixed a leaked handle that occurred when writeLayerFromTar failed, as the hcsshim.LayerWriter was never closed in this case.

- How to verify it

Verified locally during stress tests that were causing leaked layers. I've not leaked a layer in days, where before this fix they were leaking regularily.

- Description for the changelog

Fixed a layer leak on Windows.

@johnstep @jhowardmsft

Copy link
Member

@johnstep johnstep left a comment

Choose a reason for hiding this comment

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

LGTM

@lowenna
Copy link
Member

lowenna commented Mar 29, 2018

LGTM. Nice find. (Although nit, I'm not a fan of named return variables)

@lowenna
Copy link
Member

lowenna commented Mar 29, 2018

@carlfischer1 - for backport consideration

@darstahl
Copy link
Contributor Author

@jhowardmsft Agreed, but in cases like this, named return values are the only safe way to prevent variable shadowing causing err in the defer to be a different err than what is being returned. I think this pattern is the safest way to do this.

@codecov
Copy link

codecov bot commented Mar 30, 2018

Codecov Report

Merging #36728 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master   #36728      +/-   ##
==========================================
- Coverage   35.21%   35.19%   -0.02%     
==========================================
  Files         614      614              
  Lines       45645    45645              
==========================================
- Hits        16073    16067       -6     
- Misses      27441    27447       +6     
  Partials     2131     2131

func writeLayer(layerData io.Reader, home string, id string, parentLayerPaths ...string) (int64, error) {
err := winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege, winio.SeRestorePrivilege})
func writeLayer(layerData io.Reader, home string, id string, parentLayerPaths ...string) (size int64, err error) {
err = winio.EnableProcessPrivileges([]string{winio.SeBackupPrivilege, winio.SeRestorePrivilege})
Copy link
Member

Choose a reason for hiding this comment

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

@jhowardmsft would renaming the err output variable to retErr address your concerns?

I know we've had cases where the output variable was overlooked, and naming it retErr instead of plain err makes it a bit more apparent that it's an output variable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that change. Changed to use retErr to prevent confusion.

@thaJeztah
Copy link
Member

ping @jhowardmsft @johnstep PTAL if the latest version still LGTY

return 0, err
}
defer func() {
if err2 := w.Close(); err2 != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to rename err2 to err since that no longer conflicts with the return name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. Done.

Signed-off-by: Darren Stahl <darst@microsoft.com>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM - looks like all comments are addressed (thanks!)

@mback2k
Copy link

mback2k commented Oct 30, 2020

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

windows: docker system prune not reclaiming expected space
8 participants