Skip to content

Dagger call hangs on telemetry draining #7048

Closed

Description

@jedevc

To reproduce on main (can also repro against v0.11.0 using the new modularized ci on main):

$ dagger call --source=. sdk go generate entries
sdk
(hangs here, even though the task is complete)

Dumping trace logs on the engine:

time="2024-04-08T11:58:34Z" level=trace msg="server removed" client_call_digest= client_hostname=daggerdoer client_id=jui8v1z5en9a42r1l9sncx1zp server_id=cl0so4twc5tpx6ggse1v4rpxa
time="2024-04-08T11:58:34Z" level=debug msg="session call done" client_call_digest= client_hostname=daggerdoer client_id=jui8v1z5en9a42r1l9sncx1zp register_client=true server_id=cl0so4twc5tpx6ggse1v4rpxa
time="2024-04-08T11:58:34Z" level=debug msg="exporting spans to pubsub" call=uvo90qb6cll202ijuzbgxa7ww spans=1
time="2024-04-08T11:58:34Z" level=debug msg="pubsub exporting span" call=uvo90qb6cll202ijuzbgxa7ww endTime="2024-04-08 11:58:34.317715668 +0000 UTC" id=6ce54437520d9481 span=moby.buildkit.v1.Control/Session status=Error trace=ad1f63c1d21669763c9995a867fa80ce
time="2024-04-08T11:58:34Z" level=debug msg="exporting spans to subscriber" spans=1 trace=ad1f63c1d21669763c9995a867fa80ce
time="2024-04-08T11:58:34Z" level=debug msg="waiting for spans" activeSpans=1 draining=true immediate=false trace=ad1f63c1d21669763c9995a867fa80ce
time="2024-04-08T11:58:34Z" level=debug msg="waiting for span" activeSpans=1 draining=true id=63b55c6f67dff984 immediate=false span=moby.buildkit.v1.Control/Session trace=ad1f63c1d21669763c9995a867fa80ce

The moby.buildkit.v1.Control/Session never seems to complete, so the client never seems to finish telemetry:

if err := c.telemetry.Wait(); err != nil {
rerr = errors.Join(rerr, fmt.Errorf("flush telemetry: %w", err))
}

Not quite sure what's special about the sdk go generate job specifically, but it seems to consistently cause this hang on v0.11.0+. cc @vito, any ideas?

Activity

  1. added this to the v0.11.1 milestone on Apr 8, 2024
  2. jedevc commented on Apr 8, 2024

    @jedevc
    ContributorAuthor

    Aha, I've found a reproducer - there appears to be something up with the ExperimentalPrivilegedNesting option being used in a dependent service.

    Threw together an integration test:

    func TestModuleNestedServiceHang(t *testing.T) {
    	t.Parallel()
    	c, ctx := connect(t)
    
    	_, err := c.Container().From(golangImage).
    		WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
    		WithWorkdir("/work/").
    		With(daggerExec("init", "--source=.", "--name=hang", "--sdk=go")).
    		WithNewFile("/work/main.go", dagger.ContainerWithNewFileOpts{
    			Contents: `package main
     			import (
     				"context"
     			)
    			type Hang struct{}
    			func (m *Hang) Try(ctx context.Context) error {
    				svc := dag.Container().
    					From("nginx").
    					WithExposedPort(80).
    					WithExec(nil, ContainerWithExecOpts{
    						ExperimentalPrivilegedNesting: true,
    					}).
    					AsService()
    				ctr := dag.Container().
    					From("alpine").
    					WithServiceBinding("website", svc).
    					WithExec([]string{"echo", "foo"})
    				_, err := ctr.Sync(ctx)
    				return err
    			}
     			`,
    		}).
    		With(daggerCall(`try`)).
    		Stdout(ctx)
    	require.NoError(t, err)
    }
  3. vito commented on Apr 8, 2024

    @vito
    Contributor

    The telemetry draining is super conservative and waits for all in-flight spans to complete. My guess is that nesting starts a span corresponding to the nested session, but the process that spawned it just gets kill -9ed from somewhere (e.g. ctx cancellation but not sure about the repro above) and is never able to cleanly end its child spans.

    For example, right now canceling/interrupting actually has to workaround this to avoid hanging because ctx cancellation just does a kill -9, so if you poorly time that (and e.g. kill -9 a Function that is running a child span) it'd lead to a hang. Instead we give interruption some kind of "immediate" flag that tells it not to wait for all spans.

    It's also possible we make the draining less conservative, but it's that way for a reason - showing unfinished spans in Cloud or the TUI is super confusing.

    Maybe the long-term fix is to always implement "soft" cancellation, but that's hard because Buildkit doesn't expose that capability outside of the gateway API.

    Another alternative could be "if a parent span exited, don't wait for its child spans" - but technically OpenTelemetry does not prescribe this behavior, for example you can have a parent span that spawns an async child span that outlives its parent. But still, maybe this would work best for us?

  4. modified the milestones: v0.11.1, next on Apr 9, 2024
  5. jedevc commented on Apr 9, 2024

    @jedevc
    ContributorAuthor

    Bringing this out of the milestone, while technically this is a regression, this is fairly low priority IMO, since #7049 avoids this issue for us (we only hit it because of a misconfiguration in the first place).

  6. sipsma commented on May 17, 2024

    @sipsma
    Contributor

    Cross-posting this comment: #7387 (comment)

    There's an integ test that repros hanging on OTEL draining easily and some ExtraDebug logs attached

  7. removed this from the next milestone on Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions