Uh oh!
There was an error while loading. Please reload this page.
plugin: closer-based plugin notification socket - #4905
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@## master #4905 +/- ##
==========================================
+ Coverage 61.71% 61.78% +0.06%
==========================================
Files 289 289 Lines 20241 20267 +26 ==========================================
+ Hits 12492 12521 +29 + Misses 6863 6859 -4 - Partials 886 887 +1 |
neersighted
left a comment
There was a problem hiding this comment.
An excellent simplification. I've been on a bit of a "use more contexts" kick recently, but I don't know how I totally overlooked them as the ideal/correct synchronization primitive here.
I'd like to see the loop used to handle plugin connections simplified a bit.
In addition, two other thoughts:
- FreeBSD doesn't appear to have anonymous sockets either, so really we appear to have "the Linuxes" (Windows + Linux) and "the Berkley Unixes." Based on that, I think we should have a
socket_linux_windowsand asocket_nolinux_nowindowsinstead of the current arrangement. - To make things flow a little smoother, why not make
listen()return theUnixAddrpointer so we don't have to pull it back out of the listener and typecast it?
Uh oh!
There was an error while loading. Please reload this page.
Benehiko
commented
Mar 1, 2024
yeah honestly I think this is a better solution. I guess based on your comment (#4878 (comment)) we would use a pattern similar to funcSocketListener(ctx context.Context, hfunc(context.Context, net.UnixConn) error ) {
for {
// accept connconn, err:=l.Accept()
// send it off to the handlergoh(ctx, conn)
}
}In the above example, we spawn many conn instances that are used inside the handler |
cpuguy83
commented
Mar 1, 2024
Can we use this for anything other than just closing it without breaking existing plugins? |
cpuguy83
commented
Mar 1, 2024
To clarify: If the plugin is never expecting to receive data on this socket and is only waiting for a read to return, I'm not sure it is possible to re-use the same socket without breaking those assumptions. |
neersighted
commented
Mar 2, 2024
The existing code does a busy-read, discarding any data read until an EOF is reached, upon which it cancels the CLI plugin context (which should terminate the process). |
thaJeztah
commented
Mar 4, 2024
Looks like the linter is complaining; |
With my suggested changes the shadowing the linter complains about should go away. |
laurazard
left a comment
There was a problem hiding this comment.
Really nice change overall, thanks!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
72a6233 to
0b44902Comparecpuguy83
commented
Mar 4, 2024
I've updated this:
|
neersighted
left a comment
There was a problem hiding this comment.
I see you're thinking a fair bit more elaborately/with an eye to implementing the connection-handling code sooner than later. Thanks!
A couple minor nits, otherwise LGTM.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
krissetto
left a comment
There was a problem hiding this comment.
Overall LGTM after the other small suggestions are in, thanks!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
0b44902 to
4a09dc0Compare
neersighted
left a comment
There was a problem hiding this comment.
I've carried the requested review changes; LGTM now with @cpuguy83's own review.
f7889f7 to
ef7991bCompareef7991b to
1f9ffd8ComparethaJeztah
commented
Mar 21, 2024
Failure looks to be in this area? |
1f9ffd8 to
a984f97Compare
Yes; @cpuguy83 added the ability to reconnect to the server, instead of it being a one-shot. This means we can no longer do the eager unlink (so, we're back to the behavior @krissetto expected, where we unlink at the end of the lifecycle); it is now more possible to 'leak' sockets if the process is ungracefully terminated, but that seems to be the cost of the paradigm shift to the PluginServer. I've refactored the code around this, and pushed a new version that makes this behavior explicit and passes all tests. |
cpuguy83
commented
Mar 21, 2024
Sorry I forgot I had some changes pending here. |
No problem! Does my set of changes look good to you (I kept reconnection as a feature, which meant dropping the early unlink... Before the |
cpuguy83
commented
Mar 21, 2024
LGTM, it won't let me approve it officially since its my own PR. |
This changes things to rely on a plugin server that manages all connections made to the server. An optional handler can be passed into the server when the caller wants to do extra things with the connection. It is the caller's responsibility to close the server. When the server is closed, first all existing connections are closed (and new connections are prevented). Now the signal loop only needs to close the server and not deal with `net.Conn`'s directly (or double-indirects as the case was before this change). The socket, when present in the filesystem, is no longer unlinked eagerly, as reconnections require it to be present for the lifecycle of the plugin server. Co-authored-by: Bjorn Neergaard <bjorn.neergaard@docker.com> Signed-off-by: Brian Goff <cpuguy83@gmail.com> Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
a984f97 to
d68cc0eCompare
This changes things to rely on a plugin server that manages all
connections made to the server.
An optional handler can be passed into the server when the caller wants
to do extra things with the connection.
It is the caller's responsibility to close the server.
When the server is closed, first all existing connections are closed
(and new connections are prevented).
Now the signal loop only needs to close the server and not deal with
net.Conn's directly (or double-indirects as the case was before thischange).
The socket, when present in the filesystem, is no longer unlinked
eagerly, as reconnections require it to be present for the lifecycle of
the plugin server.