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

tutorial-3: question is there a session leak? #16

Open
dibalavs opened this issue Oct 6, 2018 · 0 comments
Open

tutorial-3: question is there a session leak? #16

dibalavs opened this issue Oct 6, 2018 · 0 comments

Comments

@dibalavs
Copy link

dibalavs commented Oct 6, 2018

file handlers.go:
function:
func (s *service) GetRepo() Repository { return &VesselRepository{s.session.Clone()} }

returns clone of current session.
then later:

func (s *service) Create(ctx context.Context, req *pb.Vessel, res *pb.Response) error {
	defer s.GetRepo().Close()
	if err := s.GetRepo().Create(req); err != nil {
		return err
	}
	res.Vessel = req
	res.Created = true
	return nil
}

at the exitting of the function,
defer s.GetRepo().Close()
will produce clone of session, during s.GetRepo() call and then close it.
Why do we need this?

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

No branches or pull requests

1 participant