Skip to content

Commit

Permalink
api/auth: fix invalid mgo session
Browse files Browse the repository at this point in the history
This patch updates the outdated mgo package to the community version
github.com/globalsign/mgo to fix the issue that the mgo session cannot
be used after the primary node shutdown and re-elected.

Related issue: globalsign/mgo#5
  • Loading branch information
babygoat committed Jul 21, 2021
1 parent ce8a6a1 commit 6584064
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 34 deletions.
2 changes: 1 addition & 1 deletion controllers/controller-factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (

"github.com/twreporter/go-api/internal/news"

"github.com/globalsign/mgo"
"github.com/jinzhu/gorm"
"github.com/twreporter/go-api/globals"
"github.com/twreporter/go-api/services"
"github.com/twreporter/go-api/storage"
"github.com/twreporter/go-api/utils"
"go.mongodb.org/mongo-driver/mongo"
"gopkg.in/mgo.v2"
)

// ControllerFactory generates controlloers by given persistent storage connection
Expand Down
28 changes: 15 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.12

require (
cloud.google.com/go v0.52.0 // indirect
github.com/algolia/algoliasearch-client-go v2.25.0+incompatible
github.com/algolia/algoliasearch-client-go/v3 v3.16.0
github.com/auth0/go-jwt-middleware v0.0.0-20170425171159-5493cabe49f7
github.com/aws/aws-sdk-go v1.34.28
Expand All @@ -13,45 +12,48 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 // indirect
github.com/gin-contrib/cors v0.0.0-20170708080947-567de1916927
github.com/gin-contrib/sessions v0.0.0-20180827025425-58cbcf30135c
github.com/gin-gonic/gin v1.5.0
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/gin-contrib/sessions v0.0.3
github.com/gin-gonic/gin v1.6.3
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
github.com/go-playground/validator/v10 v10.7.0 // indirect
github.com/go-sql-driver/mysql v1.5.0
github.com/gofrs/uuid v3.2.0+incompatible // indirect
github.com/golang-migrate/migrate/v4 v4.6.1
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.1.1
github.com/gorilla/mux v1.7.2 // indirect
github.com/gorilla/sessions v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
github.com/jinzhu/copier v0.0.0-20180308034124-7e38e58719c3
github.com/jinzhu/gorm v1.9.2
github.com/jinzhu/inflection v0.0.0-20170102125226-1c35d901db3d // indirect
github.com/jinzhu/now v1.0.1 // indirect
github.com/json-iterator/go v1.1.9 // indirect
github.com/kidstuff/mongostore v0.0.0-20180412085134-db2a8b4fac1f // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lib/pq v1.1.1 // indirect
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.4.2
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a // indirect
github.com/spf13/viper v1.3.2
github.com/stretchr/testify v1.6.1
github.com/twreporter/logformatter v0.0.0-20200211094126-60fe42618206
github.com/ugorji/go v1.2.6 // indirect
go.mongodb.org/mongo-driver v1.4.6
golang.org/x/crypto v0.0.0-20200210222208-86ce3cb69678
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
google.golang.org/genproto v0.0.0-20200211035748-55294c81d784 // indirect
google.golang.org/grpc v1.27.1 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/go-playground/validator.v8 v8.18.2
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
gopkg.in/guregu/null.v3 v3.4.0
gopkg.in/matryer/try.v1 v1.0.0-20150601225556-312d2599e12e
gopkg.in/mgo.v2 v2.0.0-20160818020120-3f83fa500528
gopkg.in/yaml.v2 v2.4.0 // indirect
)

replace (
Expand Down
76 changes: 62 additions & 14 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion storage/errors.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package storage

import (
"github.com/globalsign/mgo"
"github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
"github.com/pkg/errors"
"gopkg.in/mgo.v2"
)

// ErrRecordNotFound record not found error, happens when haven't find any matched data when looking up with a struct
Expand Down
2 changes: 1 addition & 1 deletion tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/algolia/algoliasearch-client-go/v3/algolia/search"

"github.com/gin-gonic/gin"
"github.com/globalsign/mgo"
"github.com/jinzhu/gorm"
"github.com/stretchr/testify/assert"
"github.com/twreporter/go-api/configs"
Expand All @@ -25,7 +26,6 @@ import (
"github.com/twreporter/go-api/storage"
"github.com/twreporter/go-api/utils"
mongodriver "go.mongodb.org/mongo-driver/mongo"
"gopkg.in/mgo.v2"
)

var Globs globalVariables
Expand Down
4 changes: 2 additions & 2 deletions tests/pre_test_environment_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

"go.mongodb.org/mongo-driver/mongo/options"

"github.com/globalsign/mgo"
"github.com/globalsign/mgo/bson"
"github.com/jinzhu/gorm"
mongodriver "go.mongodb.org/mongo-driver/mongo"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"

"github.com/twreporter/go-api/globals"
"github.com/twreporter/go-api/internal/mongo"
Expand Down
2 changes: 1 addition & 1 deletion tests/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package tests

import (
"github.com/gin-gonic/gin"
"github.com/globalsign/mgo"
"github.com/jinzhu/gorm"
"gopkg.in/mgo.v2"
)

type defaultVariables struct {
Expand Down
2 changes: 1 addition & 1 deletion utils/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"time"

"github.com/globalsign/mgo"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/mysql"
_ "github.com/golang-migrate/migrate/v4/source/file"
Expand All @@ -17,7 +18,6 @@ import (
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
"gopkg.in/matryer/try.v1"
"gopkg.in/mgo.v2"

"github.com/twreporter/go-api/globals"
"github.com/twreporter/go-api/models"
Expand Down

0 comments on commit 6584064

Please sign in to comment.