Skip to content

Creating a Sudo() Client copy leads to nil pointer dereference #195

Closed

Description

I create the connections like this. yet when I check with a debugger, the SudoClient seems to have nil as it's connection. I'm guessing it should either have a pointer to the original, or a copy of the original one? Is it a bug or am I doing something wrong?

// setupHost configures and connects to a single host
func setupHost(hostConfig *HostConfig) (*Host, error) {
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	conn, err := createConnection(hostConfig)
	if err != nil {
		return nil, err
	}
	client, err := rig.NewClient(rig.WithConnection(conn), rig.WithLogger(logger.Slog))
	if err != nil {
		return nil, fmt.Errorf("failed to create rig client: %w", err)
	}

	err = client.Connect(ctx)
	if err != nil {
		return nil, fmt.Errorf("failed to connect: %w", err)
	}

	// Initialize sudo client at the same time
	sudoClient := client.Sudo()
	if sudoClient == nil {
		return nil, fmt.Errorf("failed to initialize sudo client")
	}

	return &Host{Client: client, Sudo: sudoClient, Vars: hostConfig.Vars, Fs: remotefs.NewFS(client)}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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