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

🐛 [Bug]: Memory leak removal in the idempotency middleware #3262

Open
3 tasks done
sunnyyssh opened this issue Dec 25, 2024 · 1 comment · May be fixed by #3263
Open
3 tasks done

🐛 [Bug]: Memory leak removal in the idempotency middleware #3262

sunnyyssh opened this issue Dec 25, 2024 · 1 comment · May be fixed by #3263
Milestone

Comments

@sunnyyssh
Copy link

Feature Proposal Description

The MemoryLock in locker.go is implemented so that allocated mutexes won't be collected by GC because it holds pointers to them even when it is not needed.
To be accurate:
It allocates new mutex for every idempotency key (and removes nowhere)

func (l *MemoryLock) Lock(key string) error {
	l.mu.Lock()
	mu, ok := l.keys[key]
	if !ok {
		mu = new(sync.Mutex)
		l.keys[key] = mu
	}
	l.mu.Unlock()

	mu.Lock()

	return nil
}

It might seem be okay until some calculations are made:
Imagine we have a server handling 1000 rps with idempotency keys. Every mutex holds 8 bytes.
So in 1 month of continuous work it will be 8 * 1000 * 60 * 60 * 24 * 30 = 20736000000 B = 19.312 GB

I propose key removal from map to allow GC collect unused Mutex. (Associated PR is created)

Alignment with Express API

N/A

HTTP RFC Standards Compliance

N/A

API Stability

N/A

Feature Examples

N/A

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have searched for existing issues that describe my proposal before opening this one.
  • I understand that a proposal that does not meet these guidelines may be closed without explanation.
Copy link

welcome bot commented Dec 25, 2024

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@gaby gaby added this to v3 Dec 25, 2024
@gaby gaby moved this to In Progress in v3 Dec 25, 2024
@gaby gaby added this to the v3 milestone Dec 25, 2024
@gaby gaby changed the title 📝 [Proposal]: Memory leak removal in the idempotency middleware 🐛 [Bug]: Memory leak removal in the idempotency middleware Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants