Skip to content

🐞 Service stop semantics work differently between SDK and Modules #6430

Closed

Description

@marcosnils

What is the issue?

Initially repoted by @matipan here: https://discord.com/channels/707636530424053791/1120503349599543376/1196809237150584995

Given the current function

func (m *Foo) Nginx(ctx context.Context) error {
	svc := dag.Container().
		From("nginx").
		WithExposedPort(80).
		AsService()
	tunnel, err := dag.Host().Tunnel(svc).Start(ctx)
	if err != nil {
		return err
	}
	defer tunnel.Stop(ctx) 

	endpoint, err := tunnel.Endpoint(ctx)
	if err != nil {
		return err
	}

	res, err := http.Get("http://" + endpoint + "/")
	if err != nil {
		return err
	}
	defer res.Body.Close()
	io.Copy(os.Stdout, res.Body)
	return nil
}

upon calling dagger call nginx, dagger will hang for a long time in the defer tunnel.Stop(ctx) call. If instead of just stopping the tunnel, we stop both the service and the tunnel in the defer function, this works as intended.

This doesn't happen while using the SDK directly without modules, the defer statement described in the example returns immediately.

Dagger version

v0.9.6

Steps to reproduce

Run the snippet above withing a context of a module.

Log output

No response

Activity

  1. added
    kind/bug
    on Jan 16, 2024
  2. jedevc commented on Jan 29, 2024

    @jedevc
    Contributor

    This looks unrelated to #6354.

    We seem to get stuck in

    dagger/core/service.go

    Lines 585 to 587 in 8483a5e

    for _, closeListener := range closers {
    errs = append(errs, closeListener())
    }

    We never shut down the connection:

    n, err := conn.Read(data)
    if err != nil {
    return
    }

    We need to make sure to properly shut down our outgoing connections, or we'll just keep reading and reading forever (see #6518). Not 100% sure why this only appears in modules, but for some reason... it doesn't.

  3. removed
    kind/bug
    on May 31, 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