Closed buger closed 1 month ago
API Changes
--- prev.txt 2024-10-24 14:55:14.112053711 +0000
+++ current.txt 2024-10-24 14:55:11.080028306 +0000
@@ -10802,11 +10802,15 @@
NewSyncForcer returns a new syncforcer with a connected redis with a key
prefix synchronizer-group- for group synchronization control.
+func (sf *SyncronizerForcer) GetIsFirstConnection() bool
+
func (sf *SyncronizerForcer) GroupLoginCallback(userKey string, groupID string) interface{}
GroupLoginCallback checks if the groupID key exists in the storage to turn
on/off ForceSync param. If the the key doesn't exists in the storage,
it creates it and set ForceSync to true
+func (sf *SyncronizerForcer) SetFirstConnection(isFirstConnection bool)
+
# Package: ./signature_validator
package signature_validator // import "github.com/TykTechnologies/tyk/signature_validator"
Here are some key observations to aid the review process:
**π« Ticket compliance analysis β ** **[6642](https://github.com/TykTechnologies/tyk/issues/6642) - Fully compliant** Fully compliant requirements: - Ensure that API keys are not deleted during synchronization interruptions. - Maintain consistency of key data between master and slave Redis instances. |
β±οΈ Estimated effort to review: 3 π΅π΅π΅βͺβͺ |
π§ͺ No relevant tests |
π No security concerns identified |
β‘ Recommended focus areas for review Error Handling The error handling logic might cause recursive calls without proper exit conditions, potentially leading to stack overflow. Singleton Implementation The singleton pattern implementation for SyncronizerForcer might not be thread-safe due to the check outside the synchronized block. |
Explore these optional code suggestions:
Category | Suggestion | Score |
Best practice |
Handle errors from the store connection attempt to ensure robustness___ **Consider handling the error returned bysf.store.Connect() to ensure that the connection is established successfully before proceeding.** [rpc/synchronization_forcer.go [27]](https://github.com/TykTechnologies/tyk/pull/6667/files#diff-97417011065a292f63eeb6fb031afbcfffa75cb3fc7073f8431add277b250c98R27-R27) ```diff -sf.store.Connect() +if err := sf.store.Connect(); err != nil { + return nil, err +} ``` Suggestion importance[1-10]: 9Why: Handling the error from `sf.store.Connect()` is crucial for ensuring the connection is established successfully. This suggestion improves robustness by preventing further operations if the connection fails. | 9 |
Possible bug |
Prevent potential infinite recursion in the
___
**Avoid potential infinite recursion by implementing a maximum recursion depth or a | 8 |
Performance |
Implement a backoff strategy to optimize resource usage during retries___ **Consider adding a backoff strategy for the retry mechanism inCheckForReload to avoid potential rapid resource exhaustion.** [gateway/rpc_storage_handler.go [806]](https://github.com/TykTechnologies/tyk/pull/6667/files#diff-8875f75b602664c44b62b67a4da41d748124ad270573a44db4ec977ee5d68021R806-R806) ```diff -time.Sleep(1 * time.Second) +time.Sleep(backoffDuration) ``` Suggestion importance[1-10]: 7Why: Introducing a backoff strategy can help prevent rapid resource exhaustion during retries, enhancing the performance and stability of the retry mechanism. | 7 |
Failed conditions
76.9% Coverage on New Code (required β₯ 80%)
C Reliability Rating on New Code (required β₯ A)
See analysis details on SonarCloud
Catch issues before they fail your Quality Gate with our IDE extension SonarLint
User description
TT-12417 Do not delete keys on synchronization (#6642)
TT-12417
Description
Avoiding key deletion when synchronizing. This will avoid having inconsistent key data between master and slave Redis.
Related Issue
https://tyktech.atlassian.net/browse/TT-12417?atlOrigin=eyJpIjoiYWNiZTdlNmYwODY5NDI1ZDkzYmQ1MWFlZjM5NGQ3ZTgiLCJwIjoiaiJ9
Motivation and Context
https://tyktech.atlassian.net/browse/TT-12417?atlOrigin=eyJpIjoiYWNiZTdlNmYwODY5NDI1ZDkzYmQ1MWFlZjM5NGQ3ZTgiLCJwIjoiaiJ9
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
PR Type
Bug fix, Enhancement
Description
SyncForcer
to ensure a single instance is used throughout the application.SetFirstConnection
andGetIsFirstConnection
to manage the initial connection state.RPCStorageHandler
by initializingSyncForcer
on unexpected errors.Changes walkthrough π
rpc_storage_handler.go
Initialize SyncForcer on RPC reload check errors
gateway/rpc_storage_handler.go
SyncForcer
instance creation withSetFirstConnection
setto true.
SyncForcer
on unexpectederrors.
synchronization_forcer.go
Implement singleton pattern and enhance SyncForcer logic
rpc/synchronization_forcer.go
SyncForcer
instance creation.SetFirstConnection
andGetIsFirstConnection
methods.GroupLoginCallback
to useisFirstConnection
for force synclogic.