Skip to content

Conversation

coadler
Copy link
Contributor

@coadler coadler commented Jul 11, 2023

Fixes: #8426

@coadler coadler self-assigned this Jul 11, 2023
@coadler coadler requested review from mafredri and johnstcn July 11, 2023 21:39
Comment on lines +352 to +383
t.Run("NotInfinite", func(t *testing.T) {
t.Parallel()
var fetchCalled uint64

cmd := &clibase.Cmd{
Handler: func(inv *clibase.Invocation) error {
buf := bytes.Buffer{}
err := cliui.Agent(inv.Context(), &buf, uuid.Nil, cliui.AgentOptions{
FetchInterval: 10 * time.Millisecond,
Fetch: func(ctx context.Context, agentID uuid.UUID) (codersdk.WorkspaceAgent, error) {
atomic.AddUint64(&fetchCalled, 1)

return codersdk.WorkspaceAgent{
Status: codersdk.WorkspaceAgentConnected,
LifecycleState: codersdk.WorkspaceAgentLifecycleReady,
}, nil
},
})
if err != nil {
return err
}

require.Never(t, func() bool {
called := atomic.LoadUint64(&fetchCalled)
return called > 5 || called == 0
}, time.Second, 100*time.Millisecond)

return nil
},
}
require.NoError(t, cmd.Invoke().Run())
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:chefs-kiss:

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks for fixing this!

@@ -15,13 +15,16 @@ var errAgentShuttingDown = xerrors.New("agent is shutting down")

type AgentOptions struct {
FetchInterval time.Duration
Fetch func(context.Context) (codersdk.WorkspaceAgent, error)
Fetch func(ctx context.Context, agentID uuid.UUID) (codersdk.WorkspaceAgent, error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad you made this change too (to pass agent ID)!

@johnstcn
Copy link
Member

Can confirm that starting lots of parallel coder ssh invocations no longer kills the database.

@coadler coadler merged commit 1c3bfac into main Jul 12, 2023
@coadler coadler deleted the colin/ssh-agent-infinite branch July 12, 2023 15:21
@github-actions github-actions bot locked and limited conversation to collaborators Jul 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cli: ssh: open SSH connection keeps hitting /api/v2/workspaceagents/{workspaceagent}
3 participants