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

conncache - skip caching errors #5418

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

egor-ryashin
Copy link
Contributor

@egor-ryashin egor-ryashin commented Aug 8, 2024

Depends on this #5218

@egor-ryashin egor-ryashin changed the title conncache - don't cache errors conncache - avoid caching errors Aug 8, 2024
@egor-ryashin egor-ryashin changed the title conncache - avoid caching errors conncache - skip caching errors Aug 8, 2024
Copy link
Contributor

@begelundmuller begelundmuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this just skips caching errors entirely? Having a TTL as described in the issue might be preferable: #5076

Also, there are CI failures.

@egor-ryashin
Copy link
Contributor Author

egor-ryashin commented Sep 12, 2024

I guess, you propose something like this:

	go func() {
		for true {
			time.Sleep(5 * time.Second)
			go func() {
				c.mu.Lock()
				defer c.mu.Unlock()
				for k, v := range c.entries {
					if v.err != nil && time.Now().Sub(v.previousErrTime) > 100*time.Second {
						c.beginClose(k, v)
					}
				}
			}()
		}
	}()

@egor-ryashin
Copy link
Contributor Author

CI fixed, need a design review.

Comment on lines 65 to 66
// The maximum time the error stays in cache
ErrorTimeout time.Duration
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It looks like this is not set anywhere?
  2. Consider calling it ErrorTTL instead since it's not a timeout the same way that OpenTimeout and CloseTimeout are

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 141 to 144
go func() {
for {
time.Sleep(5 * time.Second)
go func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing cancellation from Close. Instead of having a background loop (which adds concurrency complexity), how about just checking the TTL when accessing a cached error in Acquire? That should still ensure correctness, and cleanup for connections that are not acquired again anyway happens automatically by the LRU cache

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@egor-ryashin
Copy link
Contributor Author

Tests passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants