From ad17f3b2b3e3afdb9a0f0fa8b574c56e11330263 Mon Sep 17 00:00:00 2001 From: Jon Ayers Date: Mon, 12 Aug 2024 19:03:32 -0400 Subject: [PATCH] fix: flush after sending build log (#88) --- buildlog/coder.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/buildlog/coder.go b/buildlog/coder.go index f78664a..00ab6e9 100644 --- a/buildlog/coder.go +++ b/buildlog/coder.go @@ -83,11 +83,14 @@ func (c *agentClientV2) Send(level codersdk.LogLevel, log string) error { if err != nil { return xerrors.Errorf("send build log: %w", err) } + err = c.flush() + if err != nil { + return xerrors.Errorf("flush: %w", err) + } return nil } -func (c *agentClientV2) Close() error { - defer c.cancel() +func (c *agentClientV2) flush() error { c.ls.Flush(c.source) err := c.ls.WaitUntilEmpty(c.ctx) if err != nil { @@ -96,6 +99,11 @@ func (c *agentClientV2) Close() error { return nil } +func (c *agentClientV2) Close() error { + defer c.cancel() + return c.flush() +} + func newAgentClientV2(ctx context.Context, logger slog.Logger, client *agentsdk.Client) (CoderClient, error) { cctx, cancel := context.WithCancel(ctx) uid := uuid.New()