From 8e864d6ad3b22e77521bd2269e7843fa897b8e2b Mon Sep 17 00:00:00 2001 From: Jakov Sosic Date: Wed, 8 Dec 2021 13:30:03 +0100 Subject: [PATCH] Expose MongoDB session socket timeout as a param --- vendor/github.com/mailhog/MailHog-Server/config/config.go | 5 ++++- vendor/github.com/mailhog/storage/mongodb.go | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/vendor/github.com/mailhog/MailHog-Server/config/config.go b/vendor/github.com/mailhog/MailHog-Server/config/config.go index 59cb7061..cca700c6 100644 --- a/vendor/github.com/mailhog/MailHog-Server/config/config.go +++ b/vendor/github.com/mailhog/MailHog-Server/config/config.go @@ -21,6 +21,7 @@ func DefaultConfig() *Config { MongoURI: "127.0.0.1:27017", MongoDb: "mailhog", MongoColl: "messages", + MongoTimeout: 60, MaildirPath: "", StorageType: "memory", CORSOrigin: "", @@ -38,6 +39,7 @@ type Config struct { MongoURI string MongoDb string MongoColl string + MongoTimeout int StorageType string CORSOrigin string MaildirPath string @@ -76,7 +78,7 @@ func Configure() *Config { cfg.Storage = storage.CreateInMemory() case "mongodb": log.Println("Using MongoDB message storage") - s := storage.CreateMongoDB(cfg.MongoURI, cfg.MongoDb, cfg.MongoColl) + s := storage.CreateMongoDB(cfg.MongoURI, cfg.MongoDb, cfg.MongoColl, cfg.MongoTimeout) if s == nil { log.Println("MongoDB storage unavailable, reverting to in-memory storage") cfg.Storage = storage.CreateInMemory() @@ -124,6 +126,7 @@ func RegisterFlags() { flag.StringVar(&cfg.MongoURI, "mongo-uri", envconf.FromEnvP("MH_MONGO_URI", "127.0.0.1:27017").(string), "MongoDB URI, e.g. 127.0.0.1:27017") flag.StringVar(&cfg.MongoDb, "mongo-db", envconf.FromEnvP("MH_MONGO_DB", "mailhog").(string), "MongoDB database, e.g. mailhog") flag.StringVar(&cfg.MongoColl, "mongo-coll", envconf.FromEnvP("MH_MONGO_COLLECTION", "messages").(string), "MongoDB collection, e.g. messages") + flag.IntVar(&cfg.MongoTimeout, "mongo-timeout", envconf.FromEnvP("MH_MONGO_TIMEOUT", 60).(int), "MongoDB session socket timeout in seconds, e.g. 60") flag.StringVar(&cfg.CORSOrigin, "cors-origin", envconf.FromEnvP("MH_CORS_ORIGIN", "").(string), "CORS Access-Control-Allow-Origin header for API endpoints") flag.StringVar(&cfg.MaildirPath, "maildir-path", envconf.FromEnvP("MH_MAILDIR_PATH", "").(string), "Maildir path (if storage type is 'maildir')") flag.BoolVar(&cfg.InviteJim, "invite-jim", envconf.FromEnvP("MH_INVITE_JIM", false).(bool), "Decide whether to invite Jim (beware, he causes trouble)") diff --git a/vendor/github.com/mailhog/storage/mongodb.go b/vendor/github.com/mailhog/storage/mongodb.go index 788e2684..48570425 100644 --- a/vendor/github.com/mailhog/storage/mongodb.go +++ b/vendor/github.com/mailhog/storage/mongodb.go @@ -5,6 +5,7 @@ import ( "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" "log" + "time" ) // MongoDB represents MongoDB backed storage backend @@ -14,7 +15,7 @@ type MongoDB struct { } // CreateMongoDB creates a MongoDB backed storage backend -func CreateMongoDB(uri, db, coll string) *MongoDB { +func CreateMongoDB(uri, db, coll string, timeout int) *MongoDB { log.Printf("Connecting to MongoDB: %s\n", uri) session, err := mgo.Dial(uri) if err != nil { @@ -26,6 +27,7 @@ func CreateMongoDB(uri, db, coll string) *MongoDB { log.Printf("Failed creating index: %s", err) return nil } + session.SetSocketTimeout(time.Duration(timeout) * time.Second) return &MongoDB{ Session: session, Collection: session.DB(db).C(coll),