Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: make streaming export finalize() idempotent

Bosch126c9e4d16d1
diff --git a/internal/handlers/network_export.go b/internal/handlers/network_export.go
index 99407799..8c2d0cf5 100644
--- a/internal/handlers/network_export.go
+++ b/internal/handlers/network_export.go
@@ -9,6 +9,7 @@ import (
"path/filepath"
"strconv"
"strings"
+ "sync"
"time"
"unicode/utf8"
@@ -375,15 +376,21 @@ func (h *Handlers) HandleNetworkExportStream(w http.ResponseWriter, r *http.Requ
keepalive := time.NewTicker(15 * time.Second)
defer keepalive.Stop()
+ var finalizeOnce sync.Once
finalize := func() {
- _ = enc.Finish()
- f.Close()
- // Atomic rename on success (#8)
- if count > 0 {
- os.Rename(tmpPath, absPath)
- } else {
- os.Remove(tmpPath)
- }
+ finalizeOnce.Do(func() {
+ _ = enc.Finish()
+ if err := f.Close(); err == nil {
+ // Atomic rename on success (#8)
+ if count > 0 {
+ os.Rename(tmpPath, absPath)
+ } else {
+ os.Remove(tmpPath)
+ }
+ } else {
+ os.Remove(tmpPath)
+ }
+ })
}
for {