Skip to content

Commit

Permalink
fix: fix crash due to nil pointer (#6153)
Browse files Browse the repository at this point in the history
* fix: fix reading nil pointer source
* chore: improve debug builds
* chore: remove flaky test of frozen code
* fix: use http.NoBody when logs are empty

---------

Co-authored-by: Dawid Rusnak <dawid@drcode.pl>
  • Loading branch information
WitoDelnat and rangoo94 authored Feb 6, 2025
1 parent 40bf117 commit c9d2504
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 54 deletions.
8 changes: 4 additions & 4 deletions build/_local/agent-server.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
###################################
## Build
###################################
FROM --platform=$BUILDPLATFORM golang:1.23-alpine AS builder
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder

ARG TARGETOS
ARG TARGETARCH
ARG GOMODCACHE="/root/.cache/go-build"
ARG GOCACHE="/go/pkg"
ARG SKAFFOLD_GO_GCFLAGS

RUN apk --no-cache --update add ca-certificates && (rm -rf /var/cache/apk/* || 0)

WORKDIR /app
COPY . .
Expand All @@ -28,6 +27,8 @@ FROM golang:1.23-alpine AS debug
ENV GOTRACEBACK=all
RUN go install github.com/go-delve/delve/cmd/dlv@v1.23.1

RUN apk --no-cache --update add ca-certificates && (rm -rf /var/cache/apk/* || 0)

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /app/build/_local/agent-server /testkube/

Expand All @@ -36,10 +37,9 @@ ENTRYPOINT ["/go/bin/dlv", "exec", "--headless", "--continue", "--accept-multicl
###################################
## Distribution
###################################
FROM scratch AS dist
FROM gcr.io/distroless/static AS dist

COPY LICENSE /testkube/
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /app/build/_local/agent-server /testkube/

EXPOSE 8080
Expand Down
23 changes: 0 additions & 23 deletions contrib/executor/ginkgo/examples/e2e/e2e_suite_test.go

This file was deleted.

17 changes: 0 additions & 17 deletions contrib/executor/ginkgo/examples/e2e/url_test.go

This file was deleted.

5 changes: 3 additions & 2 deletions pkg/cloud/data/testworkflow/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,19 @@ func (r *CloudOutputRepository) SaveLog(ctx context.Context, id, workflowName st
return err
}
bufferLen := buffer.Len()
body := buffer.(io.Reader)
if bufferLen == 0 {
// http.Request won't send Content-Length: 0, if the body is non-nil
buffer.Cleanup()
buffer = nil
body = http.NoBody
} else {
defer buffer.Cleanup()
}
url, err := r.PresignSaveLog(ctx, id, workflowName)
if err != nil {
return err
}
req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, buffer)
req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, body)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/controlplaneclient/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,19 @@ func (c *client) SaveExecutionLogs(ctx context.Context, environmentId, execution
return err
}
bufferLen := buffer.Len()
body := buffer.(io.Reader)
if bufferLen == 0 {
// http.Request won't send Content-Length: 0, if the body is non-nil
buffer.Cleanup()
buffer = nil
body = http.NoBody
} else {
defer buffer.Cleanup()
}
url, err := c.SaveExecutionLogsGetPresignedURL(ctx, environmentId, executionId, legacyWorkflowName)
if err != nil {
return err
}
req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, buffer)
req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, body)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/runner/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"time"

errors2 "github.com/pkg/errors"
Expand Down Expand Up @@ -87,7 +88,7 @@ func (a *agentLoop) _saveEmptyLogs(ctx context.Context, environmentId string, ex
if execution.Workflow != nil {
workflowName = execution.Workflow.Name
}
return a.client.SaveExecutionLogs(ctx, environmentId, execution.Id, workflowName, nil)
return a.client.SaveExecutionLogs(ctx, environmentId, execution.Id, workflowName, strings.NewReader(""))
}

func (a *agentLoop) saveEmptyLogs(ctx context.Context, environmentId string, execution *testkube.TestWorkflowExecution) error {
Expand Down
16 changes: 11 additions & 5 deletions pkg/runner/executionlogswriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package runner
import (
"bufio"
"context"
"crypto/tls"
"io"
"net/http"
"sync"
Expand Down Expand Up @@ -79,18 +80,23 @@ func (e *executionLogsWriter) Save(ctx context.Context) error {
return err
}

content := e.buffer
contentLen := content.Len()
contentLen := e.buffer.Len()
body := e.buffer.(io.Reader)
if contentLen == 0 {
content = nil
body = http.NoBody
}
req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, content)
req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, body)
if err != nil {
return err
}
req.Header.Add("Content-Type", "application/octet-stream")
req.ContentLength = int64(contentLen)
res, err := http.DefaultClient.Do(req)
httpClient := http.DefaultClient
if e.skipVerify {
transport := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
httpClient.Transport = transport
}
res, err := httpClient.Do(req)
if err != nil {
return errors.Wrap(err, "failed to save file in the object storage")
}
Expand Down

0 comments on commit c9d2504

Please sign in to comment.