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

txmgr: Add closed flag and behavior to SimpleTXManager #8694

Merged
merged 5 commits into from
Jan 12, 2024

Conversation

axelKingsley
Copy link
Contributor

@axelKingsley axelKingsley commented Dec 19, 2023

What

Adds an internal flag closed to the SimpleTxManager, and uses that flag to stop new and ongoing work

Why

In situations where the BatchSubmitter is shutting down, there is ongoing work traveling through the Queue, and managed internally by the TXManager itself. This internally managed work delays shutdown, sometimes by a very long time if those transactions are being hopelessly retried.

The BatchSubmitter already Close()s the TXManager, but that close previously did not halt any work, it only closed connection to the backend. We would like to use this signal in order to more aggressively stop the transaction submission, allowing for the Batch Submitter to shut down more directly.

How

A new atomic.Bool is introduced into the SimpleTxManager. On Close(), this value is set to true. At several points in transaction submission, this flag is checked:

  • New TX Submission on the Exported Send method
  • During the CraftTX Retry Loop in send
  • During the update polling loop in sendTx
  • During the sending loop in publishTx
    If this flag is set to true, the function returns early instead of continuing to wait or retry. In the case of the update polling in sendTx, waiting for confirmations takes precedence over checking the close signal, meaning transactions that should complete are awaited, while erroring or unmined transactions are abandoned.

Tests

A new unit test has been included, demonstrating that in-flight work is cancelled early, and that new work is denied altogether.

An additional unit test has been included to show that transactions which are mined (but awaiting full confirmation) will hold the closing TxManager open until the work is complete.

Notes and Nuance

  • This should not be merged until after Canyon is settled, as abandonment of transactions has an increased potential for dangling frames, which can be painful.

@axelKingsley axelKingsley requested a review from a team as a code owner December 19, 2023 22:41
@axelKingsley axelKingsley requested a review from refcell December 19, 2023 22:41
Copy link
Contributor

coderabbitai bot commented Dec 19, 2023

Walkthrough

Walkthrough

The recent update to the transaction manager codebase revolves around handling the state when the manager is closed. An ErrClosed error is introduced, and a closed flag is added to the SimpleTxManager struct. Various methods now incorporate checks for this flag to prevent new transactions and abort ongoing ones if the manager has been closed. Additionally, new tests ensure that the closing functionality works correctly, especially when transactions are waiting for confirmation.

Changes

File Summary
op-service/txmgr/txmgr.go Added ErrClosed, introduced closed flag, and updated methods to handle the closed state.
op-service/txmgr/txmgr_test.go Added tests to validate the behavior of closing the transaction manager.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@trianglesphere trianglesphere self-assigned this Dec 20, 2023
Copy link
Member

@sebastianst sebastianst left a comment

Choose a reason for hiding this comment

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

Good first simple step to a sane txmgr shutdown!

We should also check for closed at the beginning of the retry.Do loop of send.

op-service/txmgr/txmgr_test.go Outdated Show resolved Hide resolved
op-service/txmgr/txmgr_test.go Outdated Show resolved Hide resolved
op-service/txmgr/txmgr_test.go Show resolved Hide resolved
Copy link
Member

@sebastianst sebastianst left a comment

Choose a reason for hiding this comment

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

I just realize that there might be another for loop that we probably want to break out from on a closed txmgr, the one in publishTx. It actually happened quite frequently in the past that we were stuck in a "tx underpriced" or "tx replacement underpriced" loop.

op-service/txmgr/txmgr_test.go Outdated Show resolved Hide resolved
op-service/txmgr/txmgr_test.go Outdated Show resolved Hide resolved
op-service/txmgr/txmgr_test.go Outdated Show resolved Hide resolved
op-service/txmgr/txmgr_test.go Outdated Show resolved Hide resolved
@axelKingsley axelKingsley dismissed sebastianst’s stale review January 11, 2024 18:57

issue fixed; rebased; canyon deployed

Copy link
Member

@sebastianst sebastianst left a comment

Choose a reason for hiding this comment

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

LGTM ✨

A good follow up is to check whether we call Close on the txmgr from the batcher and proposer at the right point in time, and possibly adapt logging when returned errors are ErrClose, since this is an expected returned error after the txmgr is closed.

@sebastianst sebastianst enabled auto-merge January 11, 2024 19:49
@sebastianst sebastianst changed the title Add closed flag and behavior to SimpleTXManager txmgr: Add closed flag and behavior to SimpleTXManager Jan 11, 2024
@sebastianst sebastianst added this pull request to the merge queue Jan 11, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 11, 2024
@axelKingsley axelKingsley added this pull request to the merge queue Jan 11, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jan 11, 2024
@axelKingsley axelKingsley added this pull request to the merge queue Jan 12, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 12, 2024
@axelKingsley axelKingsley added this pull request to the merge queue Jan 12, 2024
@axelKingsley axelKingsley removed this pull request from the merge queue due to a manual request Jan 12, 2024
@axelKingsley axelKingsley added this pull request to the merge queue Jan 12, 2024
Merged via the queue into develop with commit 085b83d Jan 12, 2024
65 checks passed
@axelKingsley axelKingsley deleted the feat/TXMgrShutdown branch January 12, 2024 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants