Skip to content

Commit 4e0ac15

Browse files
committed
Add buffer to channels to avoid goroutine leak
1 parent 090e0c8 commit 4e0ac15

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

cmd/ghcs/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ type getUserResult struct {
172172

173173
// getUser fetches the user record associated with the GITHUB_TOKEN
174174
func getUser(ctx context.Context, apiClient *api.API) <-chan getUserResult {
175-
ch := make(chan getUserResult)
175+
ch := make(chan getUserResult, 1)
176176
go func() {
177177
user, err := apiClient.GetUser(ctx)
178178
ch <- getUserResult{user, err}
@@ -187,7 +187,7 @@ type locationResult struct {
187187

188188
// getLocation fetches the closest Codespace datacenter region/location to the user.
189189
func getLocation(ctx context.Context, apiClient *api.API) <-chan locationResult {
190-
ch := make(chan locationResult)
190+
ch := make(chan locationResult, 1)
191191
go func() {
192192
location, err := apiClient.GetCodespaceRegionLocation(ctx)
193193
ch <- locationResult{location, err}

cmd/ghcs/ports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ type portAttribute struct {
123123
}
124124

125125
func getDevContainer(ctx context.Context, apiClient *api.API, codespace *api.Codespace) <-chan devContainerResult {
126-
ch := make(chan devContainerResult)
126+
ch := make(chan devContainerResult, 1)
127127
go func() {
128128
contents, err := apiClient.GetCodespaceRepositoryContents(ctx, codespace, ".devcontainer/devcontainer.json")
129129
if err != nil {

0 commit comments

Comments
 (0)