fix: prevent OOM by bounding io.Copy buffer usage
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 3m47s

This commit is contained in:
2025-12-18 21:09:12 +07:00
parent 7bc5a01ba7
commit 6dff735216
3 changed files with 28 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ import (
mathrand "math/rand"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"
@@ -62,6 +63,15 @@ func Getenv(key, defaultValue string) string {
return val
}
func GetBufferSize() int {
sizeStr := Getenv("BUFFER_SIZE", "32768")
size, err := strconv.Atoi(sizeStr)
if err != nil || size < 4096 || size > 1048576 {
return 32768
}
return size
}
func GenerateSSHKeyIfNotExist(keyPath string) error {
if _, err := os.Stat(keyPath); err == nil {
log.Printf("SSH key already exists at %s", keyPath)