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

Reject queries that are recursive during the resolution #2330

Merged
merged 24 commits into from
Oct 11, 2024

Conversation

xgreenx
Copy link
Collaborator

@xgreenx xgreenx commented Oct 10, 2024

If during resolution of the query we hit the same type, reject further execution. The code to do this check uses Visitor logic from the async-graphql library, but this logic is private, so I duplicated it in our branch, Later it would be nice to create PR to them in make it public. Or add a way to pass our own query validators into the async-graphql(which will be more performant).

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests

Before requesting review

  • I have reviewed the code myself

@xgreenx xgreenx requested a review from a team October 10, 2024 19:33
@xgreenx xgreenx self-assigned this Oct 10, 2024
Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

Spotted a race condition that can cause false positive recursion detections. It's not obvious to me whether this is a showstopper or not depending on how pragmatic we want to be. Let me know your thoughts. Meanwhile, I'll think about potential ways to handle this problem.

Cargo.toml Outdated
Comment on lines 146 to 151

# Add caching of the RocksDB for local development
librocksdb-sys = "0.11.0+8.1.1"

[patch.crates-io]
librocksdb-sys = { git = "https://github.com/FuelLabs/rust-rocksdb/", branch = "release/v0.21.0" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I assume we don't want to commit this part.

Suggested change
# Add caching of the RocksDB for local development
librocksdb-sys = "0.11.0+8.1.1"
[patch.crates-io]
librocksdb-sys = { git = "https://github.com/FuelLabs/rust-rocksdb/", branch = "release/v0.21.0" }


struct ValidationInner {
recursion_limit: usize,
visited: parking_lot::Mutex<HashMap<String, usize>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this so performance critical that we need the parking lot mutex instead of the std one? If we introduce parking lot, I assume we'd likely want to follow up with using their synchronization primitives everywhere (which could be a separate issue).

crates/fuel-core/src/graphql_api/validation_extension.rs Outdated Show resolved Hide resolved
netrome
netrome previously approved these changes Oct 11, 2024
Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

Nice stuff, thanks for fixing!


struct ValidationInner {
recursion_limit: usize,
errors: Mutex<Option<Vec<RuleError>>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the option here? I.e. is it meaningful to differentiate between an empty vec of errors and no errors? Otherwise I think we can simplify this to

Suggested change
errors: Mutex<Option<Vec<RuleError>>>,
errors: Mutex<Vec<RuleError>>,

@xgreenx xgreenx requested a review from a team October 11, 2024 12:58
Copy link
Member

@rymnc rymnc left a comment

Choose a reason for hiding this comment

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

can we use the image generated by this pr on devnet before merging?

rymnc
rymnc previously approved these changes Oct 11, 2024
Copy link
Member

@rymnc rymnc left a comment

Choose a reason for hiding this comment

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

maybe we need a review from @Dentosal to be able to merge.

approving so the new release isn't blocked

Dentosal
Dentosal previously approved these changes Oct 11, 2024
Copy link
Member

@Dentosal Dentosal left a comment

Choose a reason for hiding this comment

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

The code looks fine. I'm not fan of this idea at all, as having GraphQL without recursive ("graph") queries is nonsensical and just worse than a normal REST API. Have we really carried all this complexity for nothing? But given the timelines, this is the practical solution so I'm approving it anyway.

Base automatically changed from hotfix/duplicate-tx-syncing to master October 11, 2024 14:50
@xgreenx xgreenx dismissed stale reviews from Dentosal, rymnc, and netrome October 11, 2024 14:50

The base branch was changed.

@xgreenx xgreenx enabled auto-merge (squash) October 11, 2024 15:01
@xgreenx xgreenx merged commit 1372d79 into master Oct 11, 2024
33 checks passed
@xgreenx xgreenx deleted the hotfix/reject-recursive-queries-during-resolution branch October 11, 2024 15:20
@rafal-ch rafal-ch mentioned this pull request Oct 11, 2024
rafal-ch added a commit that referenced this pull request Oct 11, 2024
## Version v0.39.0

### Added
- [2324](#2324): Added metrics
for sync, async processor and for all GraphQL queries.
- [2320](#2320): Added new CLI
flag `graphql-max-resolver-recursive-depth` to limit recursion within
resolver. The default value it "1".


## Fixed
- [2320](#2320): Prevent
`/health` and `/v1/health` from being throttled by the concurrency
limiter.
- [2322](#2322): Set the
salt of genesis contracts to zero on execution.
- [2324](#2324): Ignore peer
if we already are syncing transactions from it.

#### Breaking

- [2320](#2330): Reject
queries that are recursive during the resolution of the query.

### Changed

#### Breaking
- [2311](#2311): Changed the
text of the error returned by the executor if gas overflows.

## What's Changed
* chore(executor): instrument errors to be more meaningful by @rymnc in
#2311
* fix(dummy_da_block_costs): remove dependency on polling_interval and
use channel instead by @rymnc in
#2314
* fix(txpool): Error in GossipsubMessageAcceptance variant docstrings by
@netrome in #2316
* refactor: Eager returns in txpool_v2::service::Task::run by @netrome
in #2325
* fix(api_service): exclude health checks from throttling with
ConcurrencyLimitLayer by @rymnc in
#2320
* Remove the `normalize_rewards_and_costs()` function by @rafal-ch in
#2293
* fix(genesis): set salt of contract on execution of genesis state
configuration by @rymnc in
#2322
* Fixing the issue with duplicate transaction synchronization processes
by @xgreenx in #2324
* Reject queries that are recursive during the resolution by @xgreenx in
#2330


**Full Changelog**:
v0.38.0...v0.39.0
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.

5 participants