TykTechnologies / tyk

Tyk Open Source API Gateway written in Go, supporting REST, GraphQL, TCP and gRPC protocols
Other
9.75k stars 1.09k forks source link

TT-13130 only mark the wg as done when the connection is stablished #6574

Closed sredxny closed 2 months ago

sredxny commented 2 months ago

User description

Description

When the gw is ran as edge we want this to wait until the connection is established with MDCB before attempting to pull policies and apis, we should only mark the connection waitgroup as done when the connection is successful not on every attempt

Related Issue

TT-13130

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

Checklist


PR Type

Bug fix


Description


Changes walkthrough 📝

Relevant files
Bug fix
rpc_client.go
Fix waitgroup completion logic in connection establishment

rpc/rpc_client.go
  • Removed the Done() call from the defer statement in the Dial function.
  • Added Done() call after the connection is successfully established.
  • Ensures the waitgroup is marked as done only upon successful
    connection.
  • +2/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    github-actions[bot] commented 2 months ago

    API Changes

    no api changes detected
    github-actions[bot] commented 2 months ago

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Error Handling
    Ensure that the `Done()` method is called in all code paths to prevent potential deadlocks or goroutine leaks if an error occurs before reaching the new placement of `connectionDialingWG.Done()`.
    github-actions[bot] commented 2 months ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Ensure proper handling of wait group decrement to avoid potential deadlocks or goroutine leaks ___ **Ensure that the connectionDialingWG.Done() is called even if an error occurs during
    the connection setup. This can be achieved by using a defer statement at the
    beginning of the connection setup block.** [rpc/rpc_client.go [298-302]](https://github.com/TykTechnologies/tyk/pull/6574/files#diff-3b88914c99bb9418e44e6389ce73579843562e8900730b380d7fff2e95c51033R298-R302) ```diff +defer connectionDialingWG.Done() conn.Write([]byte("proto2")) conn.Write([]byte{byte(len(connID))}) conn.Write([]byte(connID)) -// only mark as done is connection is established -connectionDialingWG.Done() ```
    Suggestion importance[1-10]: 9 Why: The suggestion correctly identifies a potential issue where `connectionDialingWG.Done()` may not be called if an error occurs before the connection is fully established. Using `defer` ensures that the wait group is decremented regardless of the outcome, preventing potential deadlocks or goroutine leaks. This is a crucial improvement for the reliability of the connection handling logic.
    9
    sonarcloud[bot] commented 2 months ago

    Quality Gate Failed Quality Gate failed

    Failed conditions
    0.0% Coverage on New Code (required ≥ 80%)

    See analysis details on SonarCloud

    sredxny commented 2 months ago

    /release to release-5-lts

    tykbot[bot] commented 2 months ago

    Working on it! Note that it can take a few minutes.

    tykbot[bot] commented 2 months ago

    @sredxny Succesfully merged PR

    sredxny commented 2 months ago

    /release to release-5.3

    sredxny commented 2 months ago

    /release to release-5.3

    tykbot[bot] commented 2 months ago

    Working on it! Note that it can take a few minutes.

    tykbot[bot] commented 2 months ago

    @sredxny Succesfully merged PR

    sredxny commented 2 months ago

    /release to release-5.3.6

    tykbot[bot] commented 2 months ago

    Working on it! Note that it can take a few minutes.

    tykbot[bot] commented 2 months ago

    @sredxny Succesfully merged PR

    sredxny commented 2 months ago

    /release to release-5.6

    tykbot[bot] commented 2 months ago

    Working on it! Note that it can take a few minutes.

    tykbot[bot] commented 2 months ago

    @sredxny Succesfully merged PR

    sredxny commented 2 months ago

    /release to release-5.6.0

    tykbot[bot] commented 2 months ago

    Working on it! Note that it can take a few minutes.

    tykbot[bot] commented 2 months ago

    @sredxny Succesfully merged PR