-
Notifications
You must be signed in to change notification settings - Fork 2.1k
plugin: closer-based plugin notification socket #4905
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
|
yeah honestly I think this is a better solution. I guess based on your comment (#4878 (comment)) we would use a pattern similar to func SocketListener(ctx context.Context, h func(context.Context, net.UnixConn) error ) {
for {
// accept conn
conn, err := l.Accept()
// send it off to the handler
go h(ctx, conn)
}
}In the above example, we spawn many conn instances that are used inside the handler |
|
Can we use this for anything other than just closing it without breaking existing plugins? |
|
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. |
|
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). |
|
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice change overall, thanks!
72a6233 to
0b44902
Compare
|
I've updated this:
|
Benehiko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff! :)
neersighted
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
krissetto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM after the other small suggestions are in, thanks!
0b44902 to
4a09dc0
Compare
neersighted
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've carried the requested review changes; LGTM now with @cpuguy83's own review.
f7889f7 to
ef7991b
Compare
Benehiko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ef7991b to
1f9ffd8
Compare
|
Failure looks to be in this area? |
1f9ffd8 to
a984f97
Compare
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. |
Benehiko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
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 |
|
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 <[email protected]> Signed-off-by: Brian Goff <[email protected]> Signed-off-by: Bjorn Neergaard <[email protected]>
a984f97 to
d68cc0e
Compare
laurazard
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
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.