websocket not close if initFunc returns an error
- 主要语言
- Go
- 星标
- 10.8k
- 派生
- 1.3k
- 平均合并
- 2 天 36 分钟
- 30 天内合并 PR
- 26
描述
### What happened?
When the `initFunc` of the `transport.Websocket{}` return an error the websocket is not close but spam the init function
### What did you expect?
The websocket is closed and only one request is made to the serveur
### Minimal graphql.schema and models to reproduce
you can use the [websocket example](https://github.com/99designs/gqlgen/tree/master/_examples/websocket-initfunc/server) from gqlgen repo
### versions
- `go run github.com/99designs/gqlgen version`? v0.17.20
- `go version`? go1.19.2 darwin/arm64
### More
You can run the [code of the example](https://github.com/99designs/gqlgen/tree/master/_examples/websocket-initfunc/server) as is or just add a debug print to make the things clear in the websocketInit:
```
func webSocketInit(ctx context.Context, initPayload transport.InitPayload) (context.Context, error) {
// Get the token from payload
any := initPayload["authToken"]
token, ok := any.(string)
if !ok || token == "" {
fmt.Println("error in init")
return nil, errors.New("authToken not found in transport payload")
}
// Perform token verification and authentication...
userId := "john.doe" // e.g. userId, err := GetUserFromAuthentication(token)
// put it in context
ctxNew := context.WithValue(ctx, "username", userId)
return ctxNew, nil
}
```
and then just run a query in the playground without any auth header:
```
subscription test {
subscribe(subscriber:"jj")
}
```
the browser will be hanging in a loading cycle and the server is looping in the init function:
```
➜ websocket_gqlgen ./server
2022/12/20 09:40:56 connect to http://localhost:8080/ for GraphQL playground
error in init
error in init
error in init
error in init
error in init
...
```
贡献指南
评估
这个 Issue 还没有评估数据。