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

Fix OOM bug #290

Merged
merged 1 commit into from
Feb 13, 2024
Merged

Fix OOM bug #290

merged 1 commit into from
Feb 13, 2024

Conversation

anishnaik
Copy link
Collaborator

@anishnaik anishnaik commented Feb 9, 2024

There existed an OOM bug due to the use of go-ethereum stateDB trie's cache. This cache does not have an eviction policy and thus will persist in memory until explicitly reset or wiped through its API (see Limitations in the fastCache documentation).

Thus, any objects that reference this cache, the stateDB (which in turn means the TestChain), will never get wiped from the heap by Go's garbage collector.

Note that we do not want to get rid of caching since it leads to magnitude improvements in throughput. Thus, the fix is two-fold:

  1. We had to update medusa-geth to have an exposed function that would allow medusa to directly reset the fast cache. See this commit.
  2. We have to now explicitly reset the cache before the FuzzerWorker is destroyed. This PR achieves that capability.

This PR closes #249, #237 and #200.

Note that this PR should also lead to performance improvements for long-term medusa runs since memory consumption is now more efficient.

Summary by CodeRabbit

  • Refactor
    • Improved resource management in testing environments by adding cleanup methods to prevent memory leaks.

@anishnaik anishnaik requested a review from Xenomega as a code owner February 9, 2024 16:51
Copy link

coderabbitai bot commented Feb 9, 2024

Walkthrough

The recent changes involve adding a Close method in test_chain.go to explicitly release resources, addressing potential memory leaks by resetting the state DB's cache. Additionally, fuzzer_worker.go sees the introduction of a defer statement for closing the test chain post-setup, enhancing resource management and potentially impacting fuzzing stability and performance.

Changes

Files Change Summary
chain/test_chain.go Added Close method to release resources explicitly.
fuzzing/fuzzer_worker.go Added defer statement to close test chain after setup.

Assessment against linked issues

Objective Addressed Explanation
Ensure continuous and consistent fuzzing operation without interruptions. (#249)
Improve the stability and reliability of the fuzzing process to prevent premature termination. (#249)
Optimize the fuzzing performance to maintain a steady rate of calls per second. (#249) Indirectly addressed through better resource management, but direct impact on performance unclear.
Enhance the monitoring and logging mechanisms to detect and troubleshoot fuzzing interruptions effectively. (#249) The changes do not include enhancements to monitoring or logging mechanisms.

Poem

In the land of code where the bits do hop,
A rabbit worked, no time to stop.
🐰 With a tweak and tune, it fixed the leak,
Ensuring fuzzing could continue to seek.

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.

Copy link

@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 e471c52 and 94fd420.
Files ignored due to path filters (2)
  • go.mod is excluded by: !**/*.mod
  • go.sum is excluded by: !**/*.sum
Files selected for processing (2)
  • chain/test_chain.go (1 hunks)
  • fuzzing/fuzzer_worker.go (1 hunks)
Additional comments: 2
fuzzing/fuzzer_worker.go (1)
  • 535-537: The addition of the defer statement to close the test chain object is a critical improvement for resource management, ensuring that resources are properly released to prevent memory leaks. This change directly addresses the OOM issue by ensuring the cache does not persist in memory unnecessarily.
chain/test_chain.go (1)
  • 202-208: The implementation of the Close method correctly addresses the memory leak issue by resetting the stateDB trie's cache. This change is crucial for preventing OOM issues and aligns with best practices for resource management in Go.

@Xenomega Xenomega merged commit c33ce63 into master Feb 13, 2024
9 checks passed
@Xenomega Xenomega deleted the dev/fix-oom-bug branch February 13, 2024 02:08
Leeyah-123 pushed a commit to Leeyah-123/medusa that referenced this pull request Jun 4, 2024
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.

Fuzzing stops after a while for some unknown reason
2 participants