Skip to content

fix a remote run bug, rpc stream should be closed after pipeline cleanup. - #16588

Merged
mergify[bot] merged 3 commits into
matrixorigin:1.2-devfrom
m-schen:1.2-remoterun-fix
Jun 3, 2024
Merged

mergify[bot] merged 3 commits into
matrixorigin:1.2-devfrom
m-schen:1.2-remoterun-fix

Conversation

@m-schen

@m-schen m-schen commented Jun 3, 2024 •

Copy link
Copy Markdown
Contributor

User description

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

may related to issue https://github.com/matrixorigin/MO-Cloud/issues/2788

What this PR does / why we need it:

调整remote run情况下关闭流的时间节点,在通知pipeline结束后再关闭流。


PR Type

Bug fix


Description

  • Modified the RemoteRun function in scope.go to ensure the sender is closed after the pipeline cleanup, preventing premature closure.
  • Updated the remoteRun function in scopeRemoteRun.go to return both sender and error, improving error handling and resource management.

Changes walkthrough 📝

Relevant files
Bug fix
scope.go
Ensure sender is closed after pipeline cleanup in RemoteRun

pkg/sql/compile/scope.go

  • Modified RemoteRun function to ensure the sender is closed after
    pipeline cleanup.
  • Introduced a new variable runErr to handle errors more effectively.
  • +10/-3   
    scopeRemoteRun.go
    Modify remoteRun to return sender and error                           

    pkg/sql/compile/scopeRemoteRun.go

  • Changed remoteRun function to return both sender and error.
  • Adjusted error handling and return statements to accommodate the new
    return type.
  • +9/-10   

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @qodo-code-review

    Copy link
    Copy Markdown

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are localized to specific functions within two files, and the logic alterations are straightforward, involving error handling and resource management improvements.

    🧪 Relevant tests

    No

    ⚡ Possible issues

    Possible Bug: The sender.close() method is no longer called in a defer statement in scopeRemoteRun.go, which could potentially lead to resource leaks if new paths of execution or early returns are introduced in future modifications.

    🔒 Security concerns

    No

    @matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Jun 3, 2024
    @mergify
    mergify Bot requested a review from sukki37 June 3, 2024 04:01
    @mergify mergify Bot added the kind/bug Something isn't working label Jun 3, 2024
    @qodo-code-review

    Copy link
    Copy Markdown

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Use a defer statement to ensure sender is always closed

    To ensure that the sender is always closed even if an error occurs during the cleanup
    process, consider using a defer statement right after the sender is created.

    pkg/sql/compile/scope.go [315-317]

     if sender != nil {
    -    sender.close()
    +    defer sender.close()
     }
     
    Suggestion importance[1-10]: 8

    Why: The suggestion to use a defer statement for closing sender is crucial for preventing resource leaks, especially in error scenarios. This is a significant improvement in resource management.

    8
    Log the error before returning it when encoding the scope or process information fails

    To improve error handling, log the error before returning it when encoding the scope or
    process information fails.

    pkg/sql/compile/scopeRemoteRun.go [340-342]

     if errEncode != nil {
    +    c.proc.Errorf(s.Proc.Ctx, "Failed to encode scope: %v", errEncode)
         return nil, errEncode
     }
     
    Suggestion importance[1-10]: 7

    Why: Adding logging before returning an error is a good practice, especially in complex functions where understanding the failure point is crucial. This enhances error traceability and debugging.

    7
    Maintainability
    Refactor to handle error cases first and return early to reduce nesting

    To improve readability and maintainability, consider handling the error cases first and
    returning early, which will reduce the nesting level of the code.

    pkg/sql/compile/scopeRemoteRun.go [327-333]

    -if lastInstruction.Op == vm.Connector || lastInstruction.Op == vm.Dispatch {
    -    if err = lastInstruction.Arg.Prepare(s.Proc); err != nil {
    -        return nil, err
    -    }
    -} else {
    +if lastInstruction.Op != vm.Connector && lastInstruction.Op != vm.Dispatch {
         return nil, moerr.NewInvalidInput(c.ctx, "last operator should only be connector or dispatcher")
     }
    +if err = lastInstruction.Arg.Prepare(s.Proc); err != nil {
    +    return nil, err
    +}
     
    Suggestion importance[1-10]: 6

    Why: The suggestion improves readability and maintainability by reducing nesting through early returns for error handling. This is a good practice in Go programming.

    6

    @mergify
    mergify Bot merged commit 80a6ad5 into matrixorigin:1.2-dev Jun 3, 2024
    @aylei aylei mentioned this pull request Jun 5, 2024
    @m-schen
    m-schen deleted the 1.2-remoterun-fix branch June 18, 2024 02:34
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    Bug fix kind/bug Something isn't working Review effort [1-5]: 2 size/S Denotes a PR that changes [10,99] lines

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    4 participants