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()