Subscription ctx.Done() not closed during server shutdown
- Ngôn ngữ chính
- Go
- Star
- 10.8k
- Fork
- 1.3k
- Merge trung bình
- 2 ngày 36 phút
- Pull request đã merge (30 ngày)
- 26
Mô tả
### 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`
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.