Skip to content

Commit

Permalink
add leak detection
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-malene committed Oct 28, 2024
1 parent 31a932e commit ea83312
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions go/enclave/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package main

import (
"fmt"
"os"
"runtime/pprof"
"time"

"github.com/ten-protocol/go-ten/go/common/container"
tenflag "github.com/ten-protocol/go-ten/go/common/flag"
Expand All @@ -25,6 +28,29 @@ func main() {
panic(fmt.Errorf("unable to create config from flags - %w", err))
}

// temporary code to help identify OOM
go func() {
for {
heap, err := os.Create(fmt.Sprintf("/data/heap_%d.pprof", time.Now().UnixMilli()))
if err != nil {
panic(fmt.Errorf("could not open heap profile: %w", err))
}
err = pprof.WriteHeapProfile(heap)
if err != nil {
panic(fmt.Errorf("could not write CPU profile: %w", err))
}
stack, err := os.Create(fmt.Sprintf("/data/stack_%d.pprof", time.Now().UnixMilli()))
if err != nil {
panic(fmt.Errorf("could not open stack profile: %w", err))
}
err = pprof.Lookup("goroutine").WriteTo(stack, 1)
if err != nil {
panic(fmt.Errorf("could not write CPU profile: %w", err))
}
time.Sleep(1 * time.Hour)
}
}()

enclaveContainer := enclavecontainer.NewEnclaveContainerFromConfig(enclaveConfig)
container.Serve(enclaveContainer)
}
26 changes: 26 additions & 0 deletions go/host/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package main

import (
"fmt"
"os"
"runtime/pprof"
"time"

"github.com/ten-protocol/go-ten/go/common/container"
hostcontainer "github.com/ten-protocol/go-ten/go/host/container"
Expand All @@ -14,6 +17,29 @@ func main() {
panic(fmt.Errorf("could not parse config. Cause: %w", err))
}

// temporary code to help identify OOM
go func() {
for {
heap, err := os.Create(fmt.Sprintf("/data/heap_%d.pprof", time.Now().UnixMilli()))
if err != nil {
panic(fmt.Errorf("could not open heap profile: %w", err))
}
err = pprof.WriteHeapProfile(heap)
if err != nil {
panic(fmt.Errorf("could not write CPU profile: %w", err))
}
stack, err := os.Create(fmt.Sprintf("/data/stack_%d.pprof", time.Now().UnixMilli()))
if err != nil {
panic(fmt.Errorf("could not open stack profile: %w", err))
}
err = pprof.Lookup("goroutine").WriteTo(stack, 1)
if err != nil {
panic(fmt.Errorf("could not write CPU profile: %w", err))
}
time.Sleep(1 * time.Hour)
}
}()

hostContainer := hostcontainer.NewHostContainerFromConfig(parsedConfig, nil)
container.Serve(hostContainer)
}

0 comments on commit ea83312

Please sign in to comment.