Skip to content

Commit

Permalink
Trigger GC to run finalizers (#2771)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Jun 2, 2023
1 parent bddfa9e commit c60534b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/ferretdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"strings"
"sync"
"time"
Expand All @@ -36,6 +37,7 @@ import (
"github.com/FerretDB/FerretDB/internal/clientconn/connmetrics"
"github.com/FerretDB/FerretDB/internal/handlers/registry"
"github.com/FerretDB/FerretDB/internal/util/debug"
"github.com/FerretDB/FerretDB/internal/util/debugbuild"
"github.com/FerretDB/FerretDB/internal/util/logging"
"github.com/FerretDB/FerretDB/internal/util/state"
"github.com/FerretDB/FerretDB/internal/util/telemetry"
Expand Down Expand Up @@ -280,6 +282,14 @@ func dumpMetrics() {

// run sets up environment based on provided flags and runs FerretDB.
func run() {
// to increase a chance of resource finalizers to spot problems
if debugbuild.Enabled {
defer func() {
runtime.GC()
runtime.GC()
}()
}

info := version.Get()

if p := cli.Test.Telemetry.Package; p != "" {
Expand Down
5 changes: 5 additions & 0 deletions integration/setup/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package setup
import (
"context"
"net/http"
"runtime"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -106,4 +107,8 @@ func Shutdown() {
defer cancel()

must.NoError(jaegerExporter.Shutdown(ctx))

// to increase a chance of resource finalizers to spot problems
runtime.GC()
runtime.GC()
}

0 comments on commit c60534b

Please sign in to comment.