From 7c23565d7f2dbef935102ce3c4d5a60e58b2d166 Mon Sep 17 00:00:00 2001 From: Ian <94922205+SoggyRhino@users.noreply.github.com> Date: Sun, 19 Apr 2026 00:10:39 -0500 Subject: [PATCH 1/2] Add ignore certain connection errors, add mongo client settings --- api/configs/setup.go | 29 ++++++++++++++++++----------- api/controllers/section.go | 2 +- api/schema/objects.go | 2 +- api/server.go | 4 ++++ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/api/configs/setup.go b/api/configs/setup.go index 400934a5..cc498e78 100644 --- a/api/configs/setup.go +++ b/api/configs/setup.go @@ -14,6 +14,8 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/mongo/readconcern" + "go.mongodb.org/mongo-driver/mongo/readpref" ) type DBSingleton struct { @@ -25,18 +27,24 @@ var once sync.Once func ConnectDB() *mongo.Client { once.Do(func() { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - - client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(GetEnvMongoURI())) + clientOptions := options.Client(). + ApplyURI(GetEnvMongoURI()). + SetMinPoolSize(0). + SetMaxPoolSize(50). + SetMaxConnIdleTime(90 * time.Second). + SetRetryReads(true). + SetReadPreference(readpref.SecondaryPreferred()). + SetReadConcern(readconcern.Majority()) + + client, err := mongo.Connect(context.Background(), clientOptions) if err != nil { log.Fatalf("Unable to create MongoDB client") } - defer cancel() - // ping the database - err = client.Ping(ctx, nil) - if err != nil { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + if err = client.Ping(ctx, nil); err != nil { log.Fatalf("Unable to ping database") } @@ -115,18 +123,17 @@ var clubOnce sync.Once func ConnectClubsDB() *sql.DB { clubOnce.Do(func() { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) db, err := sql.Open("pgx", GetClubsDBUri()) if err != nil { log.Panic("Unable to connect to clubs database.") } + // ping the database + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - // ping the database - err = db.PingContext(ctx) - if err != nil { + if err = db.PingContext(ctx); err != nil { log.Panic("Unable to ping database") } diff --git a/api/controllers/section.go b/api/controllers/section.go index 58fcbd2d..c89323c3 100644 --- a/api/controllers/section.go +++ b/api/controllers/section.go @@ -355,4 +355,4 @@ func buildSectionPipeline(endpoint string, sectionQuery bson.M, paginate map[str } return append(append(append(baseStages, lookupStages...), replaceStages...), paginateStages...) -} \ No newline at end of file +} diff --git a/api/schema/objects.go b/api/schema/objects.go index ff80e04c..ebc73180 100644 --- a/api/schema/objects.go +++ b/api/schema/objects.go @@ -328,7 +328,7 @@ type AcademicCalendar struct { MidtermsDue string `bson:"midterms_due" json:"midterms_due"` UniversityClosings [][]string `bson:"university_closings" json:"university_closings"` NoClasses [][]string `bson:"no_classes" json:"no_classes"` - URL string `bson:"url" json:"url"` + URL string `bson:"url" json:"url"` } type AcademicCalendarSession struct { Name string `bson:"name" json:"name"` diff --git a/api/server.go b/api/server.go index fe8ee6d0..864c6caf 100644 --- a/api/server.go +++ b/api/server.go @@ -53,6 +53,10 @@ func main() { Dsn: "https://530f8e39f757b71ab26ad1aa12e17a4d@o4504918397353984.ingest.us.sentry.io/4509397160493056", TracesSampleRate: 1.0, EnableTracing: true, + IgnoreErrors: []string{ + "tls: internal error", + "socket was unexpectedly closed", + }, }); err != nil { log.Printf("Sentry initialization failed: %v\n", err) } From 9e725484a600f1a8e8c47efebea5e681aae060f8 Mon Sep 17 00:00:00 2001 From: Ian <94922205+SoggyRhino@users.noreply.github.com> Date: Sun, 19 Apr 2026 01:23:40 -0500 Subject: [PATCH 2/2] change mongo client options --- api/configs/setup.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/configs/setup.go b/api/configs/setup.go index cc498e78..b5862503 100644 --- a/api/configs/setup.go +++ b/api/configs/setup.go @@ -29,12 +29,12 @@ func ConnectDB() *mongo.Client { once.Do(func() { clientOptions := options.Client(). ApplyURI(GetEnvMongoURI()). - SetMinPoolSize(0). - SetMaxPoolSize(50). - SetMaxConnIdleTime(90 * time.Second). - SetRetryReads(true). + SetMinPoolSize(5). + SetMaxPoolSize(100). + SetMaxConnIdleTime(10 * time.Minute). + SetConnectTimeout(10 * time.Second). SetReadPreference(readpref.SecondaryPreferred()). - SetReadConcern(readconcern.Majority()) + SetReadConcern(readconcern.Local()) client, err := mongo.Connect(context.Background(), clientOptions) if err != nil {