From 3655d07218bafb70cf39a9b610603473ab7f0b2f Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Thu, 20 Feb 2025 08:27:30 -0800 Subject: [PATCH] Close conn on WriteResponse errors and add Nomad to CODEOWNERS (#26) Port the fix from hashicorp/net-rpc-msgpackrpc#15 **For consistency only.** To the best of my knowledge no HashiCorp tools use this code. They only use the serialization code from this package and all use hashicorp/net-rpc-msgpackrpc for RPC. Also add @hashicorp/nomad-eng to CODEOWNERS as in https://github.com/hashicorp/go-sockaddr/pull/75 Team will also need repo write access. --- .github/CODEOWNERS | 4 ++-- codec/rpc.go | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 3da71e03..f52ee4f6 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -2,7 +2,7 @@ # More on CODEOWNERS files: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners # Default owner -* @hashicorp/team-ip-compliance +* @hashicorp/team-ip-compliance @hashicorp/nomad-eng # Add override rules below. Each line is a file/folder pattern followed by one or more owners. # Being an owner means those groups or individuals will be added as reviewers to PRs affecting @@ -10,4 +10,4 @@ # Examples: # /docs/ @docs-team # *.js @js-team -# *.go @go-team \ No newline at end of file +# *.go @go-team diff --git a/codec/rpc.go b/codec/rpc.go index 3fa9f547..c64d6dca 100644 --- a/codec/rpc.go +++ b/codec/rpc.go @@ -162,7 +162,13 @@ func (c *goRpcCodec) WriteRequest(r *rpc.Request, body interface{}) error { } func (c *goRpcCodec) WriteResponse(r *rpc.Response, body interface{}) error { - return c.write(r, body, true) + err := c.write(r, body, true) + if err != nil { + // If error occurred writing a response, close the underlying connection. + // See hashicorp/net-rpc-msgpackrpc#15 + c.Close() + } + return err } func (c *goRpcCodec) ReadResponseHeader(r *rpc.Response) error {