Skip to content

Networking errors after calling Sync() on Containers that have dependent Services #6493

Closed

Description

@kpenfound

I have a pipeline with multiple Services and Containers being passed around. If a Container that has a dependent service is Sync()'ed, future calls to the Service will fail with something like:

lookup 5r4dg8qetp2iq.r4mh9kocl49fi.dagger.local on 10.87.0.1:53: no such host

psuedocode example:

foo := dag.Container().From("postgres").AsService()

bar := dag.Container().From("asdf").WithServiceBinding("db", foo).WithExec(["some", "commands])

_, err := bar.Sync()

baz := dag.Container().From("zbcd").WithServiceBinding("db", foo).WithExec(["this", "fails"])

If the bar.Sync() here is removed, the baz execution will be successful.

Activity

  1. sagikazarmark commented on Jan 26, 2024

    @sagikazarmark
    Contributor

    Same problem here: sagikazarmark/daggerverse#42

  2. jedevc commented on Jan 29, 2024

    @jedevc
    Contributor

    Based on @kpenfound's report, this works on v0.9.6, but doesn't on v0.9.7. Did a git bisect, and isolated the issue to #6425 (cc @sipsma).

    9bf9f7f303b6768efbba540376a0bd6eae6979a3 is the first bad commit
    commit 9bf9f7f303b6768efbba540376a0bd6eae6979a3
    Author: Erik Sipsma <[email protected]>
    Date:   Mon Jan 15 16:14:37 2024 -0800
    
        services: key services by server id; auto start cli service flags (#6425)
    
  3. sipsma commented on Jan 29, 2024

    @sipsma
    Contributor

    Thanks for tracking it down @jedevc! The connection between that change and this issue is extremely non-apparent at first glance, gonna need to look into it. Have 10k other things spinning atm so may not be for a few days but will get back here ASAP.

  4. self-assigned this
    on Jan 29, 2024
  5. sipsma commented on Jan 30, 2024

    @sipsma
    Contributor

    Spent a little time looking into this, I think the root problem is that #6425 intentionally results in services being shared across a single session (rather than isolated to single clients), but we continue to unconditionally stop services when any client in the session shuts down here, specifically in such a way that we don't actually update the state of the service to be "not running".

    Worked fine in previous assumptions of services being tied to the client (who cares about updating the state if it's all going away anyways) but doesn't make sense anymore. I made a naive change to just call ss.Detach on the service instead in that code, but that seems to result in everything taking forever to execute (maybe due to the detach grace period?). Reached timebox for today on this, so to be continued.

    cc @vito

  6. jedevc commented on Jan 30, 2024

    @jedevc
    Contributor

    Got a test that seems to produce the desired issue on v0.9.7, but can't seem to repro on main for whatever reason.

    func TestModuleServiceSync(t *testing.T) {
    	t.Parallel()
    
    	c, ctx := connect(t)
    
    	modGen := c.Container().From(alpineImage).
    		WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
    		WithWorkdir("/work").
    		With(daggerExec("mod", "init", "--name=playground", "--sdk=go")).
    		WithNewFile("main.go", dagger.ContainerWithNewFileOpts{
    			Contents: `
    package main
    
    import (
    	"context"
    )
    
    type Playground struct{}
    
    func (p *Playground) DoThing(ctx context.Context, sync bool) (*Container, error) {
    	svc := dag.Container().From("nginx").WithExposedPort(80).AsService()
    	foo := dag.Container().From("alpine").
    		WithExec([]string{"apk", "add", "curl"}).
    		WithServiceBinding("foo", svc).
    		WithExec([]string{"curl", "http://foo"})
    	if sync {
    		if _, err := foo.Sync(ctx); err != nil {
    			return nil, err
    		}
    	}
    	return foo, nil
    }
    `})
    	modGen, err := modGen.Sync(ctx)
    	require.NoError(t, err)
    	logGen(ctx, t, modGen.Directory("."))
    
    	out, err := modGen.
    		With(daggerQuery(`{playground{doThing(sync: false){stdout}}}`)).
    		Stdout(ctx)
    	require.NoError(t, err)  // this passes
    	require.Contains(t, out, "Welcome to nginx")
    
    	out, err = modGen.
    		With(daggerQuery(`{playground{doThing(sync: true){stdout}}}`)).
    		Stdout(ctx)
    	require.NoError(t, err)  // this fails
    	require.Contains(t, out, "Welcome to nginx")
    }
  7. jedevc commented on Jan 30, 2024

    @jedevc
    Contributor

    It's weird, because I definitely would've expected this to continue to fail.

  8. jedevc commented on Jan 30, 2024

    @jedevc
    Contributor

    specifically in such a way that we don't actually update the state of the service to be "not running".

    This is changed in #6354 - so maybe it's that

  9. vito commented on Jan 30, 2024

    @vito
    Contributor

    This is changed in #6354 - so maybe it's that

    Yep that seems to be the case - specifically we now call stop on the services tracker which deletes it from the maps 🎉

    https://github.com/dagger/dagger/pull/6354/files#diff-1ebb5e1bc419d06e30aafaf4b05f75270d16d82924c0afc6b8a2f3332d4bcd92R330

  10. jedevc commented on Jan 30, 2024

    @jedevc
    Contributor

    The timing still seems wrong, when closing a client, we shouldn't close all the services on that server IMO. So it no longer gets left in an invalid state - but I think what happens is we spin up the service, then stop it, and then start it again.

  11. vito commented on Jan 30, 2024

    @vito
    Contributor

    Oh true. I should not declare victory while bleary-eyed.

    This is tricky because the intent behind the shutdown is for it to happen synchronously as the client goes away so we don't see any services left in a running state from the event logs (e.g. in Cloud cc @marcosnils).

  12. jedevc commented on Jan 30, 2024

    @jedevc
    Contributor

    Perhaps we could do a detach like behavior, but at the server-level? Although I really wanted to avoid the last client from blocking on it, since that made the code so much neater (I guess there are legitimate reasons to do this though).

  13. nipuna-perera commented on Jan 31, 2024

    @nipuna-perera
    Contributor

    I get a similar error even without calling sync(). Basically trying to attach a docker daemon as a sidecar. Similar to this - https://github.com/kpenfound/dagger-modules/blob/main/dockerd/main.go

  14. sipsma commented on Jan 31, 2024

    @sipsma
    Contributor

    Yeah @jedevc after running again w/ your fix I can't repro with Kyle's voting app example anymore either 🎉

    To address the remaining weirdness around stopping too often, could we:

    1. Detach from services on StopClientServices when it's coming from a non-main-caller (i.e. a module function call)
    2. Force stop when the main client caller stops
      ?
  15. jedevc commented on Jan 31, 2024

    @jedevc
    Contributor

    Yah, either of those options sound totally reasonable 🎉 I'll happily pick this up, rework my test to detect the multiple stop case, and try and find a fix.

    (re-assigning to myself, but if you still want it @sipsma, feel free to steal it back 😆)

  16. assigned and unassigned on Jan 31, 2024
  17. sipsma commented on Jan 31, 2024

    @sipsma
    Contributor

    To clarify, I meant that we'd do both of those (detach when non-main-caller, force stop when main caller). But yes sounds good on you taking it from here, bandwidth is at a premium right now :-) thank you!

  18. kpenfound commented on Feb 8, 2024

    @kpenfound
    ContributorAuthor

    Confirmed things are working for my case in 0.9.8!

  19. added this to the v0.10.x milestone on Mar 1, 2024
  20. vito commented on Mar 1, 2024

    @vito
    Contributor

    Sneaking this into v0.10.x just as a way to not forget about it - seems like we still need to figure this out, since it's kinda working but super janky that it restarts services, which is hard to notice

  21. added a commit that references this issue on Mar 7, 2024
    bf34d84
  22. added a commit that references this issue on Apr 3, 2024
    6467198
  23. removed this from the next milestone on May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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