99designs / 99designs/gqlgen

Subscription ctx.Done() not closed during server shutdown

未关闭
#2,610 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Go
星标
10.8k
派生
1.3k
平均合并
2 天 36 分钟
30 天内合并 PR
26

描述

### What happened?

We have long running graphql subscriptions for tracking things like online status updates that we define like this:
```
func (r *subscriptionResolver) Online(ctx context.Context) (<-chan *model.OnlineUpdates, error) {
onlineEvents := make(chan *model.OnlineUpdates, 1)
doSomeSetup()
go func() {
for {
select {
case <-ctx.Done():
doSomeCleanup()
default:
sendUpdates(onlineEvents)
}
}
}
return onlineEvents, nil
}
```

This is currently working exactly how we'd expect for a running server. If the client closes the subscription websocket, then the `ctx.Done()` channel gets closed and triggers our cleanup code, which does things like marking the user as offline in our data store, and other such things.

The problem comes in when the server gets shutdown by calling something like `http.Server.Shutdown()`. In this case, it appears that the subscription channels themselves get closed, but the actual `ctx.Done()` channel never gets closed, presumably because cancel never gets called on the Context. This means that our cleanup code never gets called.

### What did you expect?

`ctx.Done()` to get closed when the http server is shutdown.

### versions
- `go run github.com/99designs/gqlgen version`: `v0.17.28`
- `go version`: `go version go1.20.2 darwin/arm64`

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。