graphql: fix nil deref on a timer (#27978)

graphql: fix the panic of nil timer.Stop

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
Delweng 2023-08-23 15:47:42 +08:00 committed by GitHub
parent 16946d218a
commit c31f9cf23a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,7 +88,9 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
response := h.Schema.Exec(ctx, params.Query, params.OperationName, params.Variables)
timer.Stop()
if timer != nil {
timer.Stop()
}
responded.Do(func() {
responseJSON, err := json.Marshal(response)
if err != nil {