Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent OOM cases with closed channels. #1611

Open
fogfish opened this issue Oct 16, 2024 · 1 comment
Open

Prevent OOM cases with closed channels. #1611

fogfish opened this issue Oct 16, 2024 · 1 comment
Labels
needs-triage Newly filed issue that needs triage

Comments

@fogfish
Copy link

fogfish commented Oct 16, 2024

The following program runs with Out of Memory due to forgotten return statement after "ctrl" channel is closed. Would there be any possibility for capturing the cases through code analysis?

package main

import (
	"fmt"
	"time"
)

func main() {
	ctrl := make(chan struct{})

	go func() {
		for {
			select {
			case <-ctrl:
			case <-time.After(5 * time.Second):
				fmt.Printf("==> print status\n")
			}
		}
	}()

	time.Sleep(10 * time.Second)
	close(ctrl)

	// OOM: here

	time.Sleep(3600 * time.Second)
}
@fogfish fogfish added the needs-triage Newly filed issue that needs triage label Oct 16, 2024
@fogfish
Copy link
Author

fogfish commented Oct 16, 2024

The issue has been fixed in Go 1.23 https://pkg.go.dev/time#After.
I think worth spending time, WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Newly filed issue that needs triage
Projects
None yet
Development

No branches or pull requests

1 participant