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

RPCServer: close chan when Serve returns #217

Merged
merged 1 commit into from Oct 12, 2022

Conversation

fairclothjm
Copy link
Contributor

Ensure the RPCServer Serve function closes the DoneCh when it returns. Add a test that will hang if we don't close the channel.

Fixes #216

Log diff after changes using the basic example

diff --git a/rpc.log b/rpc.log
index c7237c7..b8ca295 100644
--- a/rpc.log
+++ b/rpc.log
@@ -7,7 +7,6 @@
 [DEBUG] plugin: using plugin: version=1
 [DEBUG] plugin.greeter: message from GreeterHello.Greet: timestamp=NORMALIZED
 Hello!
-[DEBUG] plugin.greeter: NORMALIZED [ERR] plugin: stream copy 'stderr' error: stream closed
 [DEBUG] plugin.greeter: NORMALIZED [DEBUG] plugin: plugin server: accept unix NORMALIZED: use of closed network connection
 [INFO]  plugin: plugin process exited: path=./plugin/greeter pid=NORMALIZED
 [DEBUG] plugin: plugin exited
Test output
Wed Oct 12 09:39:19 CDT 2022
--- PASS: TestClient_testInterfaceReattach (2.01s)
--- PASS: TestClient (0.01s)
--- PASS: TestClient_killStart (0.01s)
--- PASS: TestClient_testCleanup (0.01s)
--- PASS: TestClient_testInterface (0.01s)
--- PASS: TestClient_grpc_servercrash (0.01s)
--- PASS: TestClient_grpc (0.01s)
--- PASS: TestClient_grpcNotAllowed (0.01s)
--- PASS: TestClient_grpcSyncStdio (0.03s)
--- PASS: TestClient_cmdAndReattach (0.00s)
--- PASS: TestClient_reattach (1.01s)
--- PASS: TestClient_reattachNoProtocol (1.01s)
--- PASS: TestClient_reattachGRPC (1.01s)
--- PASS: TestClient_reattachNotFound (0.01s)
--- PASS: TestClientStart_badVersion (0.01s)
--- PASS: TestClientStart_badNegotiatedVersion (0.01s)
--- PASS: TestClient_Start_Timeout (0.05s)
--- PASS: TestClient_Stderr (0.02s)
--- PASS: TestClient_StderrJSON (0.02s)
--- PASS: TestClient_textLogLevel (0.02s)
--- PASS: TestClient_Stdin (0.09s)
--- PASS: TestClient_SecureConfig (0.10s)
--- PASS: TestClient_TLS (0.03s)
--- PASS: TestClient_TLS_grpc (0.02s)
--- PASS: TestClient_secureConfigAndReattach (0.00s)
--- PASS: TestClient_ping (0.01s)
--- PASS: TestClient_wrongVersion (0.01s)
--- PASS: TestClient_legacyClient (0.01s)
--- PASS: TestClient_legacyServer (2.01s)
--- PASS: TestClient_versionedClient (0.02s)
--- PASS: TestClient_mtlsClient (0.06s)
--- PASS: TestClient_mtlsNetRPCClient (0.05s)
--- PASS: TestClient_logger (0.43s)
--- PASS: TestClient_logStderr (0.00s)
--- PASS: TestBasicError_ImplementsError (0.00s)
--- PASS: TestBasicError_MatchesMessage (0.00s)
--- PASS: TestNewBasicError_nil (0.00s)
--- PASS: TestGRPCClient_App (0.00s)
--- PASS: TestGRPCConn_BidirectionalPing (0.00s)
--- PASS: TestGRPCC_Stream (0.00s)
--- PASS: TestGRPCClient_Ping (0.00s)
--- PASS: TestGRPCClient_Reflection (0.00s)
--- PASS: TestHelperProcess (0.00s)
--- PASS: TestClient_App (0.00s)
--- PASS: TestClient_syncStreams (0.10s)
--- PASS: TestServer_testMode (0.00s)
--- PASS: TestServer_RPC (0.00s)
--- PASS: TestServer_testMode_AutoMTLS (0.08s)
--- PASS: TestRmListener_impl (0.00s)
--- PASS: TestRmListener (0.00s)
--- PASS: TestProtocolSelection_no_server (0.00s)
--- PASS: TestServer_testStdLogger (0.00s)
ok  	github.com/hashicorp/go-plugin	9.010s

Copy link
Contributor

@swenson swenson left a comment

Choose a reason for hiding this comment

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

LGTM; makes sense.

I'm not 100% sure it matters in most normal use cases sense in non-test scenarios, the Serve() function will call os.Exit().

@fairclothjm fairclothjm merged commit 118b62a into master Oct 12, 2022
@fairclothjm fairclothjm deleted the fix-rpc-serve-close-chan branch October 12, 2022 20:54
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.

RPCServer should close DoneCh when return
2 participants