graphql-python / graphql-python/graphql-core

Cancel resolver tasks if execution of an operation is terminated

未關閉
#217 8 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
help wanted investigate
主要語言
Python
星號
531
分支
146
PR 合併指標
30 天內沒有已合併 PR

描述

### TL;DR

Would it be possible to cancel outstanding resolver tasks ~as soon as~ _before_ execution of a GraphQL operation is terminated? Outstanding / unused tasks can happen as a result of an incoercible field resolver error.

These outstanding tasks can run well after lifecycle hooks responsible for cleaning up their context have completed. As a result, they often fail and cause a lot of noisy errors for us.

### More details

Hello!

I'm coming from the `strawberry-graphql` project. We're running into a problem with abandoned resolver tasks not being cancelled, and thus failing in unpredictable ways.

Strawberry has an [extensions framework](https://strawberry.rocks/docs/guides/custom-extensions#execution-context) which allows you to wrap the execution phase of your operation processing in hooks – running code before and after execution of resolvers. We use these hooks to manage (set up and tear down) some state needed by the resolvers.

However, when a resolver of a non-nullable field fails, it may lead to the results of some other resolvers being no longer necessary. It appears that `graphql-core` will then short-circuit returning a result, while the no-longer-necessary resolvers are still running. We see that they can continue running well after the HTTP response was returned.

The problem is that Strawberry's lifecycle hooks (and I also imagine - the webserver's) would have completed by that time. As a result, we do things like terminate the DB session – making it very likely that these outstanding tasks will fail with various esoteric errors. This causes a lot of noise in our observability suite – which we'd love to avoid.

See https://github.com/strawberry-graphql/strawberry/issues/3414 for more details, and https://github.com/strawberry-graphql/strawberry/issues/3414#issuecomment-2012060461 for the comment which recommends I report the issue here.

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

首先追蹤非同步 GraphQL 操作的執行,以及當不可為 null 的 resolver 失敗時 resolver 工作如何被排程。重現 issue #3414 中描述的 Strawberry 情境;完成的標準是:不再需要的 resolver 工作會在執行終止前被取消,且不會在回應或生命週期清理後繼續執行。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
graphql, python
領域
api, backend
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。