Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: ensure agent conn routine is closed before exit#6900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kylecarbs merged 1 commit intomainfromagentexit
Mar 30, 2023
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletioncodersdk/agentsdk/agentsdk.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -161,12 +161,15 @@ func (c *Client) Listen(ctx context.Context) (net.Conn, error) {
return nil, codersdk.ReadBodyAsError(res)
}

ctx, cancelFunc := context.WithCancel(ctx)
ctx, wsNetConn := websocketNetConn(ctx, conn, websocket.MessageBinary)

// Ping once every 30 seconds to ensure that the websocket is alive. If we
// don't get a response within 30s we kill the websocket and reconnect.
// See: https://github.com/coder/coder/pull/5824
closed := make(chan struct{})
go func() {
defer close(closed)
tick := 30 * time.Second
ticker := time.NewTicker(tick)
defer ticker.Stop()
Expand DownExpand Up@@ -199,7 +202,13 @@ func (c *Client) Listen(ctx context.Context) (net.Conn, error) {
}
}()

return wsNetConn, nil
return &closeNetConn{
Conn: wsNetConn,
closeFunc: func() {
cancelFunc()
<-closed
},
}, nil
}

type PostAppHealthsRequest struct {
Expand DownExpand Up@@ -623,3 +632,13 @@ type StartupLogsNotifyMessage struct {
CreatedAfter int64 `json:"created_after"`
EndOfLogs bool `json:"end_of_logs"`
}

type closeNetConn struct {
net.Conn
closeFunc func()
}

func (c *closeNetConn) Close() error {
c.closeFunc()
return c.Conn.Close()
}

[8]ページ先頭

©2009-2025 Movatter.jp