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

Close backendConn after use #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions proxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error
fullMethodName := lowLevelServerStream.Method()
// We require that the director's returned context inherits from the serverStream.Context().
outgoingCtx, backendConn, err := s.director(serverStream.Context(), fullMethodName)
defer backendConn.Close()
Copy link

@vgough vgough Dec 7, 2019

Choose a reason for hiding this comment

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

This should go through the director, IMO. Also this shouldn't occur unless the call succeeds, otherwise you can get a NPE panic since backendConn may be nil.

Need for backend cleanup was noted in #16, which I've implemented on a separate branch: https://github.com/vgough/grpc-proxy/blob/master/proxy/handler.go#L71

Choose a reason for hiding this comment

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

Hi @vgough. Isn't it enough to just 'defer backendConn.Close()' after checking if director returned an error to prevent nil pointer dereference

Copy link

Choose a reason for hiding this comment

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

You're responding to a comment that's over 4 years old. I'm not using this anymore. Be sure to test your setup under load. Yes, at the very minimum there should be a nil check to avoid a NPE.


clientCtx, clientCancel := context.WithCancel(outgoingCtx)
if err != nil {
return err
Expand Down