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

Bug: Goroutine leak incoderd.(*api).workspaceAgentTurn #1508

Closed
Assignees
mafredri
Labels
apiArea: HTTP API
@mafredri

Description

@mafredri

There seems to be a goroutine leak incoderd.(*api).workspaceAgentTurn.

This could be seen as two bugs:

  1. Goroutine leak
  2. Use of(*http.Request).Context() afterHijack in more than one place

Steps to Reproduce

  1. Enable pprof for coder server
  2. coder ssh dev
  3. ctlr+d
  4. Goto 1
  5. Check pprof (go tool pprof -http=:8080 http://localhost:6060/debug/pprof/goroutine)

The leak is in part due to reliance on thehttp.Request context and use of websockets. The underlying websocket library calls(*http.Request).Hijack which disables context propagation.

This happens here:

wsConn,err:=websocket.Accept(rw,r,&websocket.AcceptOptions{

And the following contexts will not cancel until the http handler completes:

netConn:=websocket.NetConn(r.Context(),wsConn,websocket.MessageBinary)

case<-r.Context().Done():

We must avoid usingr.Context() after hijack, unless we are using it with the expectation that the http handler will exit (at which point the context will complete).

I'm unfamiliar with thepion/turn package, but another factor could be wrt how it handles connection closure, perhaps it does not propagate as we expect since we're not callingwsConn.Close() due to context reliance?


Similar reliance on request context after hijack is done elsewhere, we should rethink all of them. Example:

resource,err:=api.Database.GetWorkspaceResourceByID(r.Context(),workspaceAgent.ResourceID)

Metadata

Metadata

Assignees

Labels

apiArea: HTTP API

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp