Skip to content

chore(cache): start once for service endpoint cache#74

Merged
Jacobbrewer1 merged 2 commits intomainfrom
chore/cache-start-once
May 7, 2025
Merged

chore(cache): start once for service endpoint cache#74
Jacobbrewer1 merged 2 commits intomainfrom
chore/cache-start-once

Conversation

@Jacobbrewer1
Copy link
Owner

Describe your changes

This pull request includes updates to improve thread safety, error handling, and type assertion practices across multiple files. The most significant changes involve introducing a sync.Once mechanism to ensure the Start method is only executed once in ServiceEndpointHashBucket, improving error handling in the same method, and updating type assertion syntax for consistency.

Thread safety improvements:

  • Added a sync.Once instance (startOnce) to ServiceEndpointHashBucket to ensure the Start method is executed only once. This prevents potential race conditions when initializing the hash bucket. (cache/service_endpoint_hash_bucket.go, cache/service_endpoint_hash_bucket.goL29-R39)

Error handling enhancements:

  • Refactored the Start method in ServiceEndpointHashBucket to use startErr for consistent error propagation within the sync.Once block. This ensures that errors encountered during initialization are properly returned. (cache/service_endpoint_hash_bucket.go, [1] [2]

Type assertion consistency:

  • Updated type assertions for FixedHashBucket, ServiceEndpointHashBucket, and dedupeHandler to use the (*Type)(nil) pattern instead of new(Type). This is a more idiomatic approach in Go for ensuring interface compliance. (cache/fixed_hash_bucket.go, [1]; cache/service_endpoint_hash_bucket.go, [2]; logging/dedupe_handler.go, [3]

@Jacobbrewer1 Jacobbrewer1 marked this pull request as ready for review May 7, 2025 10:09
Copilot AI review requested due to automatic review settings May 7, 2025 10:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the thread safety and error handling for the service endpoint cache while standardizing type assertions across several files.

  • Introduces a sync.Once mechanism and improved error propagation in the Start method of ServiceEndpointHashBucket.
  • Updates type assertions in FixedHashBucket, ServiceEndpointHashBucket, and dedupeHandler to the idiomatic (*Type)(nil) pattern.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
logging/dedupe_handler.go Updated type assertion for dedupeHandler to the idiomatic pointer pattern.
cache/service_endpoint_hash_bucket.go Added sync.Once to ensure Start is executed only once with enhanced error handling.
cache/fixed_hash_bucket.go Updated type assertion for FixedHashBucket to the idiomatic pointer pattern.

@Jacobbrewer1 Jacobbrewer1 enabled auto-merge (squash) May 7, 2025 10:09
@Jacobbrewer1 Jacobbrewer1 merged commit f0806c2 into main May 7, 2025
6 checks passed
@Jacobbrewer1 Jacobbrewer1 deleted the chore/cache-start-once branch May 7, 2025 10:12
@github-actions
Copy link

github-actions bot commented Jun 7, 2025

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants