Skip to content

Commit 325cf76

Browse files
committed
Close conn on WriteResponse errors
See hashicorp/net-rpc-msgpackrpc#15 for details.
1 parent bc22f4e commit 325cf76

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

codec/rpc.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,13 @@ func (c *goRpcCodec) WriteRequest(r *rpc.Request, body interface{}) error {
162162
}
163163

164164
func (c *goRpcCodec) WriteResponse(r *rpc.Response, body interface{}) error {
165-
return c.write(r, body, true)
165+
err := c.write(r, body, true)
166+
if err != nil {
167+
// If error occurred writing a response, close the underlying connection.
168+
// See hashicorp/net-rpc-msgpackrpc#15
169+
c.Close()
170+
}
171+
return err
166172
}
167173

168174
func (c *goRpcCodec) ReadResponseHeader(r *rpc.Response) error {

0 commit comments

Comments
 (0)