fix: stream only new logs back to client after starting server

This commit is contained in:
2026-03-23 21:31:32 +01:00
parent 6c1e9b236e
commit 908adf4468

View File

@@ -8,6 +8,7 @@ import (
"io" "io"
"strconv" "strconv"
"sync" "sync"
"time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
dockerclient "github.com/docker/docker/client" dockerclient "github.com/docker/docker/client"
@@ -25,14 +26,14 @@ func NewDockerLogStreamer(client *dockerclient.Client) *DockerLogStreamer {
} }
func (s *DockerLogStreamer) Start(ctx context.Context, server *model.Server, handleLine func(string)) error { func (s *DockerLogStreamer) Start(ctx context.Context, server *model.Server, handleLine func(string)) error {
if _, exists := s.cancels.Load(server.ID); exists { s.Stop(server.ID)
return nil
}
if server.ContainerID == "" { if server.ContainerID == "" {
logging.Warn("DockerLogStreamer.Start: no container ID for server %s, skipping", server.ID) logging.Warn("DockerLogStreamer.Start: no container ID for server %s, skipping", server.ID)
return nil return nil
} }
since := time.Now().UTC().Format(time.RFC3339)
streamCtx, cancel := context.WithCancel(ctx) streamCtx, cancel := context.WithCancel(ctx)
s.cancels.Store(server.ID, cancel) s.cancels.Store(server.ID, cancel)
@@ -44,6 +45,7 @@ func (s *DockerLogStreamer) Start(ctx context.Context, server *model.Server, han
ShowStderr: true, ShowStderr: true,
Follow: true, Follow: true,
Timestamps: false, Timestamps: false,
Since: since,
}) })
if err != nil { if err != nil {
logging.Error("DockerLogStreamer: failed to attach to container %s: %v", server.ContainerID[:12], err) logging.Error("DockerLogStreamer: failed to attach to container %s: %v", server.ContainerID[:12], err)