Title: Bug: Goroutine leak in `coderd.(*api).workspaceAgentTurn` · Issue #1508 · coder/coder · GitHub
Open Graph Title: Bug: Goroutine leak in `coderd.(*api).workspaceAgentTurn` · Issue #1508 · coder/coder
X Title: Bug: Goroutine leak in `coderd.(*api).workspaceAgentTurn` · Issue #1508 · coder/coder
Description: There seems to be a goroutine leak in coderd.(*api).workspaceAgentTurn. This could be seen as two bugs: Goroutine leak Use of (*http.Request).Context() after Hijack in more than one place Steps to Reproduce Enable pprof for coder server ...
Open Graph Description: There seems to be a goroutine leak in coderd.(*api).workspaceAgentTurn. This could be seen as two bugs: Goroutine leak Use of (*http.Request).Context() after Hijack in more than one place Steps to ...
X Description: There seems to be a goroutine leak in coderd.(*api).workspaceAgentTurn. This could be seen as two bugs: Goroutine leak Use of (*http.Request).Context() after Hijack in more than one place Steps to ...
Opengraph URL: https://github.com/coder/coder/issues/1508
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug: Goroutine leak in `coderd.(*api).workspaceAgentTurn`","articleBody":"There seems to be a goroutine leak in `coderd.(*api).workspaceAgentTurn`.\r\n\r\nThis could be seen as two bugs:\r\n\r\n1. Goroutine leak\r\n2. Use of `(*http.Request).Context()` after `Hijack` in more than one place\r\n\r\n## Steps to Reproduce\r\n\r\n0. Enable pprof for coder server\r\n1. `coder ssh dev`\r\n3. `ctlr+d`\r\n4. Goto 1\r\n5. Check pprof (`go tool pprof -http=:8080 http://localhost:6060/debug/pprof/goroutine`)\r\n\r\nThe leak is in part due to reliance on the `http.Request` context and use of websockets. The underlying websocket library calls `(*http.Request).Hijack` which disables context propagation.\r\n\r\nThis happens here: https://github.com/coder/coder/blob/668a6712e62a839a193544e431552744520b05df/coderd/workspaceagents.go#L304\r\n\r\nAnd the following contexts will not cancel until the http handler completes:\r\nhttps://github.com/coder/coder/blob/668a6712e62a839a193544e431552744520b05df/coderd/workspaceagents.go#L316\r\n\r\nhttps://github.com/coder/coder/blob/668a6712e62a839a193544e431552744520b05df/coderd/workspaceagents.go#L320\r\n\r\nWe must avoid using `r.Context()` after hijack, unless we are using it with the expectation that the http handler will exit (at which point the context will complete).\r\n\r\nI'm unfamiliar with the [`pion/turn`](https://github.com/pion/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 calling `wsConn.Close()` due to context reliance?\r\n\r\n---\r\n\r\nSimilar reliance on request context after hijack is done elsewhere, we should rethink all of them. Example:\r\n\r\nhttps://github.com/coder/coder/blob/668a6712e62a839a193544e431552744520b05df/coderd/workspaceagents.go#L155","author":{"url":"https://github.com/mafredri","@type":"Person","name":"mafredri"},"datePublished":"2022-05-17T13:08:09Z","url":"https://github.com/coder/coder/issues/1508"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6996a30f-a7d9-7534-a7c6-3e4cca3c05f6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9B78:14700E:21FCE14:2B0FE18:6B0176C2 |
| html-safe-nonce | 8852ecb701ae728f370f1fa9caababebbb03011511812822a3f28d01474e81f5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Qjc4OjE0NzAwRToyMUZDRTE0OjJCMEZFMTg6NkIwMTc2QzIiLCJ2aXNpdG9yX2lkIjoiNzExMzkwNDQxNzQ5NzI0OTQ3NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 46112c89ae85befb6f815f74f24f59daf9837365b91f7716fc6032773010ecc2 |
| hovercard-subject-tag | issue:1238616415 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/coder/coder/1508/issue_layout |
| twitter:image | https://opengraph.githubassets.com/446ad9ef1fd3f4f15c4bff6f3fb032c907b7657144af79289e00623528a5b842/coder/coder/issues/1508 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/446ad9ef1fd3f4f15c4bff6f3fb032c907b7657144af79289e00623528a5b842/coder/coder/issues/1508 |
| og:image:alt | There seems to be a goroutine leak in coderd.(*api).workspaceAgentTurn. This could be seen as two bugs: Goroutine leak Use of (*http.Request).Context() after Hijack in more than one place Steps to ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mafredri |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/coder/coder git https://github.com/coder/coder.git |
| octolytics-dimension-user_id | 95932066 |
| octolytics-dimension-user_login | coder |
| octolytics-dimension-repository_id | 440752086 |
| octolytics-dimension-repository_nwo | coder/coder |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 440752086 |
| octolytics-dimension-repository_network_root_nwo | coder/coder |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width