shippy
shippy copied to clipboard
tutorial-3: question is there a session leak?
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?