Apparently, on line 31, when you did mgoSession, erro := mgo.Dial(mongoDbURI), go was creating a new local-scoped mgoSession, instead of using the package-scoped one.
The package-scoped mgoSession was always nil, and the code never entered the if block on line 25.
The result was that in every call to GetMongoSession(), a new session was opened, then Copy()ed, creating 2 sessions. The copy session was closed by the caller code, but the other one remained open.
Replacing := by = on seemed to fix the issue, but then a new var erro error nedded to be added.
Apparently, on line 31, when you did
mgoSession, erro := mgo.Dial(mongoDbURI)
, go was creating a new local-scopedmgoSession
, instead of using the package-scoped one.The package-scoped
mgoSession
was always nil, and the code never entered theif
block on line 25. The result was that in every call toGetMongoSession()
, a new session was opened, thenCopy()
ed, creating 2 sessions. The copy session was closed by the caller code, but the other one remained open.Replacing
:=
by=
on seemed to fix the issue, but then a newvar erro error
nedded to be added.