diff --git a/pkg/db/addchannel.go b/pkg/db/addchannel.go index 2d8a1f5..3019247 100644 --- a/pkg/db/addchannel.go +++ b/pkg/db/addchannel.go @@ -13,7 +13,9 @@ func AddChannel(channelName string) { client := Connect() - ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + /* Get my collection instance */ diff --git a/pkg/db/connect.go b/pkg/db/connect.go index 3fe8b32..4c43740 100644 --- a/pkg/db/connect.go +++ b/pkg/db/connect.go @@ -19,7 +19,10 @@ func Connect() *mongo.Client { if err != nil { log.Fatal(err) } - ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) + + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + err = client.Connect(ctx) if err != nil { log.Fatal(err) diff --git a/pkg/db/initialjoin.go b/pkg/db/initialjoin.go index 21c2bea..1864c13 100644 --- a/pkg/db/initialjoin.go +++ b/pkg/db/initialjoin.go @@ -12,7 +12,9 @@ func InitialJoin(nb *bot.Bot) { client := Connect() collection := client.Database("nourybot").Collection("channels") - ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + defer client.Disconnect(ctx) cur, currErr := collection.Find(ctx, bson.D{})