The Wayback Machine - https://web.archive.org/web/20240627123004/https://github.com/docker/cli/pull/5146
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins: cleanup sockets when done #5146

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

laurazard
Copy link
Member

@laurazard laurazard commented Jun 11, 2024

- What I did

Since 509123f, we've been leaking sockets in the filesystem on platforms where abstract sockets aren't supported.

That change relied on Go to cleanup our sockets for us, which Go will happily do as long as we make sure to close the listener, which we weren't previously doing unless to signal the plugin to terminate.

- How I did it

This change adds a deferred call to PluginServer.Close(), which makes sure we close the plugin server at the end of the plugin execution, so that we never exit without cleaning up.

- How to verify it

Execute a plugin command with debug logging enabled (e.g. docker -D compose convert) and look for the added debug log. Also check $TMPDIR for leaked sockets.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

Screenshot 2024-06-11 at 21 32 13

@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.

Project coverage is 61.67%. Comparing base (591bd17) to head (3dcc653).
Report is 14 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5146      +/-   ##
==========================================
- Coverage   61.82%   61.67%   -0.16%     
==========================================
  Files         298      295       -3     
  Lines       20730    20778      +48     
==========================================
- Hits        12817    12815       -2     
- Misses       7000     7043      +43     
- Partials      913      920       +7     

@@ -92,6 +94,7 @@ func (pl *PluginServer) Addr() net.Addr {
//
// The error value is that of the underlying [net.Listner.Close] call.
func (pl *PluginServer) Close() error {
logrus.Debug("Closing plugin server")
Copy link
Member Author

Choose a reason for hiding this comment

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

Would you still rather I remove this line @tonistiigi? I don't really mind either way, but I expect debug logs to be quite verbose.

Copy link
Member

@tonistiigi tonistiigi Jun 11, 2024

Choose a reason for hiding this comment

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

Currently, we don't have many debug logs for commands, and for example in buildx where we use --debug for extra verbosity for build errors, this can be confusing to users who have no context for "plugin server".

Copy link
Member

Choose a reason for hiding this comment

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

Yeah the tricky bit with the CLI (unlike the daemon, where it usually ends up in a log file) is that logging in the CLI is.. printing in the user's terminal.

Would be nice if we had a location to store logs, but .. we don't, so we should not use it except for exceptional cases.

We could use "trace" level logging (one level more verbose than debug), but not sure if we pass that through currently (and not sure if containerd logs had it as option)

Copy link
Member Author

@laurazard laurazard Jun 12, 2024

Choose a reason for hiding this comment

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

Oh, that works!

logrus.Trace("Closing plugin server")
./build/docker -l trace compose version
TRAC[0000] Plugin server listening on /var/folders/zj/khjjyd1n0zjd9xc44815szxc0000gn/T/docker_cli_9e516c003cda3c20ab79b88afc18434b 
Docker Compose version v2.27.1-desktop.1
TRAC[0000] Closing plugin server                                              
./build/docker -D compose version    
Docker Compose version v2.27.1-desktop.1

Copy link
Member Author

Choose a reason for hiding this comment

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

@tonistiigi this work for you?

Copy link
Member

Choose a reason for hiding this comment

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

I think it should be fine; we can remove in a follow-up if it's a problem (but we need to look a bit at logging overall; I also did a quick attempt to see what it'd could look like if we switched over to containerd/log, as we did on the engine side; #5149

Since 509123f, we've been leaking sockets
in the filesystem on platforms where abstract sockets aren't supported.

That change relied on Go to cleanup our sockets for us, which Go will happily
do as long as we make sure to close the listener, which we weren't previously
doing unless to signal the plugin to terminate.

This change adds a deferred call to `PluginServer.Close()`, which makes sure we
close the plugin server at the end of the plugin execution, so that we never exit
without cleaning up.

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
@thaJeztah
Copy link
Member

@laurazard how difficult would it be to write a test-case for this? (could be in a follow-up if we want to get this in)

@thaJeztah
Copy link
Member

Had a quick chat; let's bring this one in, and do a follow-up for the test and any other changes we may need.

@thaJeztah thaJeztah merged commit 9dabf16 into docker:master Jun 12, 2024
88 checks passed
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.

None yet

5 participants