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

Merging to release-5.3: TT-13130 updated version of gorpc library and prevent panic on start edge (#6629) #6637

Merged

Conversation

buger
Copy link
Member

@buger buger commented Oct 14, 2024

User description

TT-13130 updated version of gorpc library and prevent panic on start edge (#6629)

User description

TT-13130
Summary Tyk Cloud: Panic appears when a user tried to deploy GW before Control Plane is in deployed state
Type Bug Bug
Status In Dev
Points N/A
Labels Re_open

Description

Moved the logic of waitgroup to be handled internally in the gorpc
library. GW only have to wait until done()

Related Issue

TT-13130

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing
    functionality to change)
  • Refactoring or add test (improvements in base code or adds test
    coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning
    why it's required
  • I would like a code coverage CI quality gate exception and have
    explained why

PR Type

Bug fix, Enhancement


Description

  • Refactored the connection dialing logic in rpc_client.go to remove
    manual sync.WaitGroup handling, leveraging the internal wait group
    management provided by the gorpc library.
  • Updated the gorpc library to a newer version in go.mod and
    go.sum, ensuring compatibility and leveraging improvements.

Changes walkthrough 📝

Relevant files
Enhancement
rpc_client.go
Refactor connection dialing wait group handling                   

rpc/rpc_client.go

  • Removed manual handling of sync.WaitGroup for connection dialing.
  • Utilized clientSingleton.ConnectionDialingWG for managing connection
    readiness.
  • +1/-7     
    Dependencies
    go.mod
    Update gorpc library version in go.mod                                     

    go.mod

    • Updated gorpc library version to latest.
    +1/-1     
    go.sum
    Update go.sum for new gorpc version                                           

    go.sum

    • Updated checksums for new gorpc library version.
    +8/-2     

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


    Co-authored-by: sredny buitrago [email protected]


    PR Type

    Bug fix, Enhancement


    Description

    • Refactored the connection dialing logic in rpc_client.go to remove manual sync.WaitGroup handling, leveraging the internal wait group management provided by the gorpc library.
    • Updated the gorpc library to a newer version in go.mod and go.sum, ensuring compatibility and leveraging improvements.

    Changes walkthrough 📝

    Relevant files
    Enhancement
    rpc_client.go
    Refactor connection dialing wait group handling                   

    rpc/rpc_client.go

  • Removed manual handling of sync.WaitGroup for connection dialing.
  • Utilized clientSingleton.ConnectionDialingWG for managing connection
    readiness.
  • +1/-8     
    Dependencies
    go.mod
    Update gorpc library version in go.mod                                     

    go.mod

    • Updated gorpc library version to the latest.
    +1/-1     
    go.sum
    Update go.sum for new gorpc version                                           

    go.sum

    • Updated checksums for new gorpc library version.
    +2/-2     

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

    …edge (#6629)
    
    <details open>
    <summary><a href="https://tyktech.atlassian.net/browse/TT-13130"
    title="TT-13130" target="_blank">TT-13130</a></summary>
      <br />
      <table>
        <tr>
          <th>Summary</th>
    <td>Tyk Cloud: Panic appears when a user tried to deploy GW before
    Control Plane is in deployed state </td>
        </tr>
        <tr>
          <th>Type</th>
          <td>
    <img alt="Bug"
    src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium"
    />
            Bug
          </td>
        </tr>
        <tr>
          <th>Status</th>
          <td>In Dev</td>
        </tr>
        <tr>
          <th>Points</th>
          <td>N/A</td>
        </tr>
        <tr>
          <th>Labels</th>
    <td><a
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20Re_open%20ORDER%20BY%20created%20DESC"
    title="Re_open">Re_open</a></td>
        </tr>
      </table>
    </details>
    <!--
      do not remove this marker as it will break jira-lint's functionality.
      added_by_jira_lint
    -->
    
    ---
    
    <!-- Provide a general summary of your changes in the Title above -->
    
    Moved the logic of waitgroup to be handled internally in the gorpc
    library. GW only have to wait until done()
    
    TT-13130
    
    <!-- Why is this change required? What problem does it solve? -->
    
    <!-- Please describe in detail how you tested your changes -->
    <!-- Include details of your testing environment, and the tests -->
    <!-- you ran to see how your change affects other areas of the code,
    etc. -->
    <!-- This information is helpful for reviewers and QA. -->
    
    <!-- What types of changes does your code introduce? Put an `x` in all
    the boxes that apply: -->
    
    - [ ] Bug fix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing
    functionality to change)
    - [ ] Refactoring or add test (improvements in base code or adds test
    coverage to functionality)
    
    <!-- Go over all the following points, and put an `x` in all the boxes
    that apply -->
    <!-- If there are no documentation updates required, mark the item as
    checked. -->
    <!-- Raise up any additional concerns not covered by the checklist. -->
    
    - [ ] I ensured that the documentation is up to date
    - [ ] I explained why this PR updates go.mod in detail with reasoning
    why it's required
    - [ ] I would like a code coverage CI quality gate exception and have
    explained why
    
    ___
    
    Bug fix, Enhancement
    
    ___
    
    - Refactored the connection dialing logic in `rpc_client.go` to remove
    manual `sync.WaitGroup` handling, leveraging the internal wait group
    management provided by the `gorpc` library.
    - Updated the `gorpc` library to a newer version in `go.mod` and
    `go.sum`, ensuring compatibility and leveraging improvements.
    
    ___
    
    <table><thead><tr><th></th><th align="left">Relevant
    files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>rpc_client.go</strong><dd><code>Refactor connection
    dialing wait group handling</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    rpc/rpc_client.go
    
    <li>Removed manual handling of <code>sync.WaitGroup</code> for
    connection dialing.<br> <li> Utilized
    <code>clientSingleton.ConnectionDialingWG</code> for managing connection
    <br>readiness.<br>
    
    </details>
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6629/files#diff-3b88914c99bb9418e44e6389ce73579843562e8900730b380d7fff2e95c51033">+1/-7</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>
    </table></td></tr><tr><td><strong>Dependencies</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>go.mod</strong><dd><code>Update gorpc library version
    in go.mod</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </dd></summary>
    <hr>
    
    go.mod
    
    - Updated `gorpc` library version to latest.
    
    </details>
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6629/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6">+1/-1</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>
    
    <tr>
      <td>
        <details>
    <summary><strong>go.sum</strong><dd><code>Update go.sum for new gorpc
    version</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    go.sum
    
    - Updated checksums for new `gorpc` library version.
    
    </details>
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6629/files#diff-3295df7234525439d778f1b282d146a4f1ff6b415248aaac074e8042d9f42d63">+8/-2</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull
    request to receive relevant information
    
    ---------
    
    Co-authored-by: sredny buitrago <[email protected]>
    
    (cherry picked from commit 6b687a2)
    Copy link
    Contributor

    github-actions bot commented Oct 14, 2024

    API Changes

    no api changes detected

    @sredxny sredxny self-requested a review October 14, 2024 13:11
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis 🔶

    6629 - Partially compliant

    Fully compliant requirements:

    • Update the gorpc library to a newer version.
    • Refactor the connection dialing logic to prevent panic when deploying GW before Control Plane is deployed.

    Not compliant requirements:

    • Ensure that the new implementation is tested and does not introduce new issues.
    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Refactoring Impact
    The refactoring removes manual sync.WaitGroup handling which could impact how connections are managed. Ensure that this change does not introduce connection handling issues or race conditions.

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Improve error handling for connection writes to enhance data integrity and error management

    Consider handling potential errors from conn.Write to ensure data integrity and
    proper error management.

    rpc/rpc_client.go [294-296]

    -conn.Write([]byte("proto2"))
    -conn.Write([]byte{byte(len(connID))})
    -conn.Write([]byte(connID))
    +if _, err := conn.Write([]byte("proto2")); err != nil {
    +  return nil, err
    +}
    +if _, err := conn.Write([]byte{byte(len(connID))}); err != nil {
    +  return nil, err
    +}
    +if _, err := conn.Write([]byte(connID)); err != nil {
    +  return nil, err
    +}
    Suggestion importance[1-10]: 9

    Why: This suggestion addresses a critical issue by adding error handling for conn.Write operations, which is essential for ensuring data integrity and preventing potential runtime errors.

    9
    Verify synchronization of WaitGroup to prevent deadlocks or runtime panics

    Ensure that the Wait on clientSingleton.ConnectionDialingWG is correctly
    synchronized with Add calls, which seem to be removed in this PR, potentially
    leading to deadlocks or panics.

    rpc/rpc_client.go [309]

    +// Ensure corresponding Add() calls are made before this Wait()
     clientSingleton.ConnectionDialingWG.Wait()
    Suggestion importance[1-10]: 8

    Why: The suggestion highlights a potential synchronization issue with the WaitGroup, which could lead to deadlocks or panics. Ensuring proper synchronization is crucial for the stability of the application.

    8
    Maintainability
    Enhance modularity and reusability by refactoring dialer configuration into a separate function

    Refactor the dialer configuration to a separate function or configuration struct to
    enhance modularity and reusability.

    rpc/rpc_client.go [262-264]

    -dialer := &net.Dialer{
    -  Timeout:   10 * time.Second,
    -  KeepAlive: 30 * time.Second,
    +dialer := getDefaultDialer()
    +...
    +func getDefaultDialer() *net.Dialer {
    +  return &net.Dialer{
    +    Timeout:   10 * time.Second,
    +    KeepAlive: 30 * time.Second,
    +  }
     }
    Suggestion importance[1-10]: 6

    Why: Refactoring the dialer configuration into a separate function improves code modularity and reusability, which is beneficial for maintainability, though it does not address any immediate functional issues.

    6
    Enhancement
    Simplify initialization of connection pool size with direct assignment

    Initialize clientSingleton.Conns directly with a default value if the configuration
    returns zero to simplify the conditional logic.

    rpc/rpc_client.go [256-258]

     clientSingleton.Conns = values.Config().RPCPoolSize
     if clientSingleton.Conns == 0 {
    -  clientSingleton.Conns = 5
    +  clientSingleton.Conns = 5  // Consider initializing directly to 5 if Config().RPCPoolSize is zero
     }
    Suggestion importance[1-10]: 3

    Why: While the suggestion offers a minor improvement in code readability by suggesting a direct assignment, it does not significantly impact the functionality or performance of the code.

    3

    Copy link

    Quality Gate Failed Quality Gate failed

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

    See analysis details on SonarCloud

    @sredxny sredxny merged commit 6adb78d into release-5.3 Oct 14, 2024
    15 of 18 checks passed
    @sredxny sredxny deleted the merge/release-5.3/6b687a22360c3c9fe516f4dcc2b6d834b7ae40b8 branch October 14, 2024 13:27
    lghiur pushed a commit that referenced this pull request Oct 14, 2024
    … prevent panic on start edge (#6629) (#6637)
    
    ### **User description**
    TT-13130 updated version of gorpc library and prevent panic on start
    edge (#6629)
    
    ### **User description**
    <details open>
    <summary><a href="https://tyktech.atlassian.net/browse/TT-13130"
    title="TT-13130" target="_blank">TT-13130</a></summary>
      <br />
      <table>
        <tr>
          <th>Summary</th>
    <td>Tyk Cloud: Panic appears when a user tried to deploy GW before
    Control Plane is in deployed state </td>
        </tr>
        <tr>
          <th>Type</th>
          <td>
    <img alt="Bug"
    
    src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium"
    />
            Bug
          </td>
        </tr>
        <tr>
          <th>Status</th>
          <td>In Dev</td>
        </tr>
        <tr>
          <th>Points</th>
          <td>N/A</td>
        </tr>
        <tr>
          <th>Labels</th>
    <td><a
    
    href="https://tyktech.atlassian.net/issues?jql=project%20%3D%20TT%20AND%20labels%20%3D%20Re_open%20ORDER%20BY%20created%20DESC"
    title="Re_open">Re_open</a></td>
        </tr>
      </table>
    </details>
    <!--
      do not remove this marker as it will break jira-lint's functionality.
      added_by_jira_lint
    -->
    
    ---
    
    <!-- Provide a general summary of your changes in the Title above -->
    
    ## Description
    
    Moved the logic of waitgroup to be handled internally in the gorpc
    library. GW only have to wait until done()
    
    ## Related Issue
    
    TT-13130
    
    ## Motivation and Context
    
    <!-- Why is this change required? What problem does it solve? -->
    
    ## How This Has Been Tested
    
    <!-- Please describe in detail how you tested your changes -->
    <!-- Include details of your testing environment, and the tests -->
    <!-- you ran to see how your change affects other areas of the code,
    etc. -->
    <!-- This information is helpful for reviewers and QA. -->
    
    ## Screenshots (if appropriate)
    
    ## Types of changes
    
    <!-- What types of changes does your code introduce? Put an `x` in all
    the boxes that apply: -->
    
    - [ ] Bug fix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Breaking change (fix or feature that would cause existing
    functionality to change)
    - [ ] Refactoring or add test (improvements in base code or adds test
    coverage to functionality)
    
    ## Checklist
    
    <!-- Go over all the following points, and put an `x` in all the boxes
    that apply -->
    <!-- If there are no documentation updates required, mark the item as
    checked. -->
    <!-- Raise up any additional concerns not covered by the checklist. -->
    
    - [ ] I ensured that the documentation is up to date
    - [ ] I explained why this PR updates go.mod in detail with reasoning
    why it's required
    - [ ] I would like a code coverage CI quality gate exception and have
    explained why
    
    
    ___
    
    ### **PR Type**
    Bug fix, Enhancement
    
    
    ___
    
    ### **Description**
    - Refactored the connection dialing logic in `rpc_client.go` to remove
    manual `sync.WaitGroup` handling, leveraging the internal wait group
    management provided by the `gorpc` library.
    - Updated the `gorpc` library to a newer version in `go.mod` and
    `go.sum`, ensuring compatibility and leveraging improvements.
    
    
    
    ___
    
    
    
    ### **Changes walkthrough** 📝
    <table><thead><tr><th></th><th align="left">Relevant
    
    files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>rpc_client.go</strong><dd><code>Refactor connection
    dialing wait group handling</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    rpc/rpc_client.go
    
    <li>Removed manual handling of <code>sync.WaitGroup</code> for
    connection dialing.<br> <li> Utilized
    <code>clientSingleton.ConnectionDialingWG</code> for managing connection
    <br>readiness.<br>
    
    
    </details>
    
    
      </td>
    <td><a
    
    href="https://github.com/TykTechnologies/tyk/pull/6629/files#diff-3b88914c99bb9418e44e6389ce73579843562e8900730b380d7fff2e95c51033">+1/-7</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>                    
    </table></td></tr><tr><td><strong>Dependencies</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>go.mod</strong><dd><code>Update gorpc library version
    in go.mod</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </dd></summary>
    <hr>
    
    go.mod
    
    - Updated `gorpc` library version to latest.
    
    
    
    </details>
    
    
      </td>
    <td><a
    
    href="https://github.com/TykTechnologies/tyk/pull/6629/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6">+1/-1</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>go.sum</strong><dd><code>Update go.sum for new gorpc
    version</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    go.sum
    
    - Updated checksums for new `gorpc` library version.
    
    
    
    </details>
    
    
      </td>
    <td><a
    
    href="https://github.com/TykTechnologies/tyk/pull/6629/files#diff-3295df7234525439d778f1b282d146a4f1ff6b415248aaac074e8042d9f42d63">+8/-2</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>                    
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull
    request to receive relevant information
    
    ---------
    
    Co-authored-by: sredny buitrago <[email protected]>
    
    
    ___
    
    ### **PR Type**
    Bug fix, Enhancement
    
    
    ___
    
    ### **Description**
    - Refactored the connection dialing logic in `rpc_client.go` to remove
    manual `sync.WaitGroup` handling, leveraging the internal wait group
    management provided by the `gorpc` library.
    - Updated the `gorpc` library to a newer version in `go.mod` and
    `go.sum`, ensuring compatibility and leveraging improvements.
    
    
    
    ___
    
    
    
    ### **Changes walkthrough** 📝
    <table><thead><tr><th></th><th align="left">Relevant
    files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>rpc_client.go</strong><dd><code>Refactor connection
    dialing wait group handling</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    rpc/rpc_client.go
    
    <li>Removed manual handling of <code>sync.WaitGroup</code> for
    connection dialing.<br> <li> Utilized
    <code>clientSingleton.ConnectionDialingWG</code> for managing connection
    <br>readiness.<br>
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6637/files#diff-3b88914c99bb9418e44e6389ce73579843562e8900730b380d7fff2e95c51033">+1/-8</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>                    
    </table></td></tr><tr><td><strong>Dependencies</strong></td><td><table>
    <tr>
      <td>
        <details>
    <summary><strong>go.mod</strong><dd><code>Update gorpc library version
    in go.mod</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; </dd></summary>
    <hr>
    
    go.mod
    
    - Updated `gorpc` library version to the latest.
    
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6637/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6">+1/-1</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>go.sum</strong><dd><code>Update go.sum for new gorpc
    version</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
    <hr>
    
    go.sum
    
    - Updated checksums for new `gorpc` library version.
    
    
    
    </details>
    
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6637/files#diff-3295df7234525439d778f1b282d146a4f1ff6b415248aaac074e8042d9f42d63">+2/-2</a>&nbsp;
    &nbsp; &nbsp; </td>
    
    </tr>                    
    </table></td></tr></tr></tbody></table>
    
    ___
    
    > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull
    request to receive relevant information
    
    ---------
    
    Co-authored-by: Sredny M <[email protected]>
    Co-authored-by: sredny buitrago <[email protected]>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants