Query timeout

A deadline on one database call, set with context.WithTimeout from the request context. When it passes, the driver cancels the query and the error wraps context.DeadlineExceeded. Reads in this course get 500 ms.

Minimal example

go
ctx, cancel := context.WithTimeout(r.Context(), 500*time.Millisecond)
defer cancel()

Learn this concept

Lesson 2.4 · database/sql: pools, contexts and timeouts

Used in exercises

Exercise 2.10 · GET /v1/restaurants with a cursor Exercise 2.24 · GET /v1/restaurants: search by name Exercise 6.6 · Request context and timeout layer
Prerequisite conceptsdatabase/sql