From 2b9a3536e78dac7a272cc23bf51e78f01f740fb7 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 26 Oct 2021 10:46:00 +0800 Subject: [PATCH] exception handling --- src/common/db/mongoModel.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/db/mongoModel.go b/src/common/db/mongoModel.go index a6e2651fe..6d315193e 100644 --- a/src/common/db/mongoModel.go +++ b/src/common/db/mongoModel.go @@ -147,7 +147,12 @@ func (d *DataBases) SaveUserChat(uid string, sendTime int64, m proto.Message) er if session == nil { return errors.New("session == nil") } - defer session.Close() + defer func() { + if session != nil { + session.Close() + } + }() + log.NewInfo("", "get mgoSession cost time", getCurrentTimestampByMill()-newTime) c := session.DB(config.Config.Mongo.DBDatabase).C(cChat)