hasura / hasura/graphql-engine
Statement timeout produces cryptic error messages for end users (`unexpected`, `database query error`)
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Is your proposal related to a problem?
For Hasura deployments which use [`statement_timeout` Database Timeouts](https://hasura.io/learn/graphql/hasura-advanced/security/6-timeouts/): if the timeout is reached, end users receive a confusing error message.
Postgres returns an error like `canceling statement due to statement timeout`, but Hasura returns a generic error:
```json
{
"errors": [
{
"extensions": {
"path": "$",
"code": "unexpected"
},
"message": "database query error"
}
]
}
```
In our case, [Chaingraph](https://chaingraph.cash/) (an open source project which uses Hasura) can be set up for hackathons and other use cases where an allow-list isn't feasible because the end users are external developers (who needed to write new, custom queries). For these cases, the docs recommend that operators [configure a new Postgres user for Hasura](https://github.com/bitauth/chaingraph/blob/master/charts/chaingraph/readme.md#using-statement_timeout) with a reasonable default `statement_timeout` setting. Other than this error message, the setup works really well.
This is the most common issue people experience with the API, and most new users think the error means either:
- **their GraphQL syntax is incorrect** and they spend time trying to fix, becoming frustrated when the error is non-deterministic (because the DB manages to run the query faster once some data is in memory)
- **our Hasura engine is unreliable/broken**
### Describe the solution you'd like
It would be fantastic if Hasura identified statement timeout errors and instead sent a more helpful error back to the user:
```JSON
{
"errors": [
{
"message": "Request cancelled due to excessive resource usage. Please limit your query and try again."
}
]
}
```
### If the feature is approved, would you be willing to submit a PR?
I'd be happy to try! I'm very new to Haskell though, so guidance would be appreciated.
(Related to: #6585)
Contributor guide
Research direction
Start by locating the Hasura engine's handling of PostgreSQL statement_timeout errors and read related issue #6585 for context. The work is done when timeout responses clearly explain that the request was cancelled for excessive resource usage instead of returning the generic database query error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell, postgresql
- Domain
- api, database
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100