shippy icon indicating copy to clipboard operation
shippy copied to clipboard

tutorial-3: question is there a session leak?

Open dibalavs opened this issue 6 years ago • 0 comments

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?

dibalavs avatar Oct 06 '18 07:10 dibalavs