superfly / flyctl

Command line tools for fly.io services
https://fly.io
Apache License 2.0
1.36k stars 224 forks source link

panic when running deploy_test.go with tags=production #3642

Closed RaghavSood closed 3 weeks ago

RaghavSood commented 3 weeks ago

Please only report specific issues with flyctl behavior. Anything like a support request for your application should go to https://community.fly.io. More people watch that space and can help you faster!

Describe the bug

I maintain the flyctl package in nixpkgs.

Our builds on darwin are failing due to an issue with how flyctl initialized the sentry-go SDK. This results in a panic within sentry-go that is triggered in TestCommand_Execute in deploy_test.go.

Specifically, flyctl initializes the sentry-go SDK as follows:

func init() {
    opts := sentry.ClientOptions{
        Dsn: "https://89fa584dc19b47a6952dd94bf72dbab4@sentry.io/4492967",
        // TODO: maybe set Debug to buildinfo.IsDev?
        // Debug:       true,
        Environment: buildinfo.Environment(),
        Release:     "v" + buildinfo.Version().String(),
        Transport: &sentry.HTTPSyncTransport{
            Timeout: 3 * time.Second,
        },
        BeforeSend: func(event *sentry.Event, _ *sentry.EventHint) *sentry.Event {
            if buildinfo.IsDev() {
                return nil
            }

            return event
        },
    }

    initError = sentry.Init(opts)
}

By initializing the sentry.HTTPSyncTransport struct directly, the ratelimit.Map under HTTPSyncTransport.limits (non-exported) receives a nil zero-value.

When the test above is run, it results in a panic within sentry-go's ratelimit.Map.Merge:

go test -tags=production -ldflags "-s -w -X github.com/superfly/flyctl/internal/buildinfo.buildDate=1970-01-01T00:00:00Z -X github.com/superfly/flyctl/internal/buildinfo.buildVersion=0.2.71" -v ./internal/command/deploy/deploy_test.go 
Stacktrace
github.com/getsentry/sentry-go/internal/ratelimit.Map.Merge(...)
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/getsentry/sentry-go@v0.28.0/internal/ratelimit/map.go:43
github.com/getsentry/sentry-go.(*HTTPSyncTransport).SendEventWithContext(0x14000697d00, {0x104284960, 0x1052c6e60}, 0x1400065cdc8)
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/getsentry/sentry-go@v0.28.0/transport.go:695 +0x554
github.com/getsentry/sentry-go.(*HTTPSyncTransport).SendEvent(0x1400065cdc8?, 0x1400065cdc8?)
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/getsentry/sentry-go@v0.28.0/transport.go:644 +0x30
github.com/getsentry/sentry-go.(*Client).processEvent(0x140002952c0, 0x1400065cdc8?, 0x14000396180, {0x10426b680, 0x1400038a5a0})
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/getsentry/sentry-go@v0.28.0/client.go:637 +0x30c
github.com/getsentry/sentry-go.(*Client).CaptureEvent(...)
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/getsentry/sentry-go@v0.28.0/client.go:447
github.com/getsentry/sentry-go.(*Client).CaptureException(0x140002952c0, {0x104267aa8?, 0x1400006a520?}, 0x14000396180, {0x10426b680, 0x1400038a5a0})
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/getsentry/sentry-go@v0.28.0/client.go:428 +0x58
github.com/getsentry/sentry-go.(*Hub).CaptureException(0x14000801950, {0x104267aa8, 0x1400006a520})
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/getsentry/sentry-go@v0.28.0/hub.go:260 +0x98
github.com/getsentry/sentry-go.CaptureException(...)
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/getsentry/sentry-go@v0.28.0/sentry.go:45
github.com/superfly/flyctl/internal/sentry.CaptureException.func1(0x1400038a5a0)
    superfly/flyctl/internal/sentry/sentry.go:92 +0x88
github.com/getsentry/sentry-go.(*Hub).WithScope(0x14000801950, 0x140000e63c8)
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/getsentry/sentry-go@v0.28.0/hub.go:200 +0x60
github.com/getsentry/sentry-go.WithScope(...)
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/getsentry/sentry-go@v0.28.0/sentry.go:91
github.com/superfly/flyctl/internal/sentry.CaptureException({0x104267aa8?, 0x1400006a520?}, {0x140000e68e0?, 0x7?, 0x0?})
    superfly/flyctl/internal/sentry/sentry.go:87 +0xd0
github.com/superfly/flyctl/internal/build/imgsrc.(*Resolver).createBuildGql(0x140001a44e0, {0x104284a08, 0x140003824b0}, {0x140001a4500, 0x2, 0x2}, 0x140000e69b8)
    superfly/flyctl/internal/build/imgsrc/resolver.go:333 +0x570
github.com/superfly/flyctl/internal/build/imgsrc.(*Resolver).createImageBuild(0x140001a44e0, {0x104284a08, 0x140003824b0}, {0x140000e6bb8?, 0x0?, 0x0?}, {{0x140005d06e0, 0xa}, {0x1400078f080, 0x3e}, ...})
    superfly/flyctl/internal/build/imgsrc/resolver.go:285 +0x180
github.com/superfly/flyctl/internal/build/imgsrc.(*Resolver).ResolveReference(0x140001a44e0, {0x104284a08, 0x14000382480}, 0x140000c70e0, {{0x140005d06e0, 0xa}, {0x1400078f080, 0x3e}, {0x103a48200, 0x43}, ...})
    superfly/flyctl/internal/build/imgsrc/resolver.go:170 +0x19c
github.com/superfly/flyctl/internal/command/deploy.determineImage({0x104284a08, 0x14000382150}, 0x140002e7e00, 0x1, 0x0)
    superfly/flyctl/internal/command/deploy/deploy_build.go:89 +0x122c
github.com/superfly/flyctl/internal/command/deploy.DeployWithConfig({0x104284a08, 0x14000382150}, 0x140002e7e00, 0x3?)
    superfly/flyctl/internal/command/deploy/deploy.go:305 +0x224
github.com/superfly/flyctl/internal/command/deploy.(*Command).run(0x1052c6e60?, {0x104284a08, 0x14000112930})
    superfly/flyctl/internal/command/deploy/deploy.go:278 +0xc18
github.com/superfly/flyctl/internal/command/deploy.New.New.newRunE.func2(0x140002d5b08, {0x1400041e000?, 0x4?, 0x103971841?})
    superfly/flyctl/internal/command/command.go:140 +0x188
github.com/spf13/cobra.(*Command).execute(0x140002d5b08, {0x14000691f20, 0x2, 0x2})
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0x840
github.com/spf13/cobra.(*Command).ExecuteC(0x140002d5b08)
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/spf13/cobra.(*Command).ExecuteContext(...)
    superfly/flyctl/.devenv/state/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1032
command-line-arguments_test.TestCommand_Execute(0x140001c8ea0)
    superfly/flyctl/internal/command/deploy/deploy_test.go:60 +0x6a8

An issue for the merge function has been filed upstream https://github.com/getsentry/sentry-go/issues/841.

This failure is accompanied by the warning WARN failed to create build in graphql: app not found: "test-basic", so my best guess is that with the tags set to production, flyctl attempts to send this to Sentry, which triggers the failure. As the init code returns nil events for non-production environments, it isn't triggered in fly's own test runs, which do not set the production tag.

However, in nixpkgs, the tags we set on the binary compilation propagate through to the tests as well, which then trigger this.