Fixed few memory leaks. Implement testing of the functionality.

This commit is contained in:
Kalzu Rekku
2026-01-08 18:55:32 +02:00
parent c663ec0431
commit 1130b7fb8c
10 changed files with 1334 additions and 13 deletions

View File

@@ -79,6 +79,10 @@ var (
startTime time.Time
health HealthStatus
healthMux sync.RWMutex
// HTTP client with timeout to prevent indefinite hangs
httpClient = &http.Client{
Timeout: 30 * time.Second,
}
)
func main() {
@@ -460,7 +464,7 @@ func handleSocket(path string, data []byte, mode string) ([]byte, error) {
func readSource(src string) ([]byte, error) {
if strings.HasPrefix(src, "http") {
resp, err := http.Get(src)
resp, err := httpClient.Get(src)
if err != nil {
return nil, err
}
@@ -477,7 +481,7 @@ func readSource(src string) ([]byte, error) {
func writeDestination(dest string, data []byte) error {
if strings.HasPrefix(dest, "http") {
resp, err := http.Post(dest, "application/json", bytes.NewBuffer(data))
resp, err := httpClient.Post(dest, "application/json", bytes.NewBuffer(data))
if err != nil {
return err
}