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

ci: fix panic in indexer #1402

Merged
merged 6 commits into from
Dec 8, 2023
Merged

ci: fix panic in indexer #1402

merged 6 commits into from
Dec 8, 2023

Conversation

MSevey
Copy link
Contributor

@MSevey MSevey commented Dec 8, 2023

Overview

3 fixes:

  1. test not using a ctx with a cancel.
  2. t.Parallel() was contributing to flakiness
  3. added ctx done check in long running for loop

Summary by CodeRabbit

  • Refactor

    • Improved transaction processing to allow non-blocking behavior and better handle context cancellation.
    • Enhanced thread safety with the addition of mutex locks in various methods to prevent race conditions.
  • Tests

    • Updated test functions to include context management and cancellation capabilities for more robust testing scenarios.

Copy link
Contributor

coderabbitai bot commented Dec 8, 2023

Walkthrough

The recent updates to the Go codebase focus on enhancing context management and thread safety. Contexts with cancellation capabilities have been introduced to certain functions, allowing for better control over goroutines. Additionally, mutex locks have been added to various methods to ensure that concurrent access to shared resources is properly synchronized, preventing race conditions.

Changes

File Path Change Summary
node/full_client_test.go Introduced context with cancellation in TestGenesisChunked and used it in newFullNode function calls.
state/txindex/indexer_service.go Modified transaction processing loop to include non-blocking select statement with context cancellation handling.
mempool/clist_mempool.go Added mutex locks and unlocks in methods resCbFirstTime, resCbRecheck, Update, TxsAvailable, and notifyTxsAvailable for thread safety.

Poem

In the land of code where the data hops around,
A rabbit worked hard without making a sound.
🥕 Locks and contexts, in harmony they blend,
Ensuring the code runs safe to the end. 🐇✨


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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

@MSevey MSevey added T:bug Something isn't working C:ci Component: Continuous Integration labels Dec 8, 2023
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9498447 and 24a0979.
Files selected for processing (1)
  • node/full_client_test.go (1 hunks)
Additional comments: 2
node/full_client_test.go (2)
  • 171-179: The changes in the TestGenesisChunked function correctly implement the addition of a cancellable context to prevent panics during test execution. The context is created and deferred cancellation is set up properly. This should enhance the test's reliability by allowing for graceful shutdowns and cleanup.

  • 176-176: The update to the newFullNode function call to use the cancellable context (ctx) instead of a background context is in line with the PR's objective to prevent test panics by allowing for context cancellation.

Copy link

codecov bot commented Dec 8, 2023

Codecov Report

Attention: 15 lines in your changes are missing coverage. Please review.

Comparison is base (21e37e9) 51.00% compared to head (d429d97) 51.09%.

Files Patch % Lines
state/txindex/indexer_service.go 21.05% 14 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1402      +/-   ##
==========================================
+ Coverage   51.00%   51.09%   +0.08%     
==========================================
  Files          46       46              
  Lines        6417     6422       +5     
==========================================
+ Hits         3273     3281       +8     
+ Misses       2804     2802       -2     
+ Partials      340      339       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MSevey MSevey marked this pull request as draft December 8, 2023 19:41
@MSevey MSevey marked this pull request as ready for review December 8, 2023 20:11
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9bdc8f6 and e860f3e.
Files selected for processing (2)
  • node/full_client_test.go (2 hunks)
  • state/txindex/indexer_service.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • node/full_client_test.go
Additional comments: 1
state/txindex/indexer_service.go (1)
  • 74-99: The changes in the loop correctly implement the non-blocking select statement to handle context cancellation signals. This allows the loop to exit gracefully when a cancellation signal is received, which aligns with the PR's objective to improve stability and context management. The error handling within the loop also seems to follow the terminateOnError pattern, which is consistent with the rest of the service's design.

@MSevey MSevey enabled auto-merge December 8, 2023 20:24
S1nus
S1nus previously approved these changes Dec 8, 2023
Manav-Aggarwal
Manav-Aggarwal previously approved these changes Dec 8, 2023
@MSevey MSevey added this pull request to the merge queue Dec 8, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 8, 2023
@S1nus S1nus added this pull request to the merge queue Dec 8, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 8, 2023
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 21e37e9 and d429d97.
Files selected for processing (3)
  • mempool/clist_mempool.go (2 hunks)
  • node/full_client_test.go (2 hunks)
  • state/txindex/indexer_service.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • mempool/clist_mempool.go
  • state/txindex/indexer_service.go
Additional comments: 1
node/full_client_test.go (1)
  • 171-179: The changes to TestGenesisChunked correctly implement the use of a cancellable context, which is passed to the newFullNode function. This aligns with the PR objectives to improve context management and cleanup in tests.

@Manav-Aggarwal Manav-Aggarwal added this pull request to the merge queue Dec 8, 2023
Merged via the queue into main with commit eccdd0f Dec 8, 2023
14 of 15 checks passed
@Manav-Aggarwal Manav-Aggarwal deleted the sevey/fix-indexer-panic branch December 8, 2023 21:13
github-merge-queue bot pushed a commit that referenced this pull request Dec 15, 2023
…l from the context cancel (#1406)

<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->

## Overview

<!-- 
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue. 
-->

The nodes were creating a new context with cancel after passing the
original context through to the services. This meant that when the node
shutdown and cancelled its context, its services did not receive a
shutdown signal until the original caller cancelled its context. This
was leading to panics in testing about writing to a logger test file
that was already closed.

This change was verified by reverting the changes in #1402 and testing
in a loop 100 times with no panics.

**EDIT 1**
Since no good deed goes unpunished 🙃 some timeouts surfaced. This was
due to `context.Background()` being used for subscribe and unsubscribe
events. Under the hood those events are watching for `ctx.Done()`
events, so when `context.Background()` is passed in, they can hang
indefinitely if the other signals aren't triggered. The test that was
most prone to this timeout was run in a loop 1000 times to verify the
issue was fixed.

Additionally, added some more checks for `ctx.Done()` for faster
shutdowns.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced node shutdown process with context cancellation for improved
service termination.
  
- **Refactor**
- Updated error handling and context management in node creation
functions.
- Improved context usage in block synchronization and event subscription
methods.
  
- **Tests**
- Adjusted full node integration tests to reflect new context
management.
  
- **Chores**
  - Removed redundant node cancellation in test cleanup function.
  
- **Documentation**
  - No visible changes to end-users.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:ci Component: Continuous Integration T:bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants