| 453 | |
| 454 | // queryContext returns a cancellable context for query execution. |
| 455 | // The cancel function is registered with the server so it can be invoked |
| 456 | // via a cancel request from another connection. |
| 457 | // The caller must call the returned cleanup function when the query completes. |
| 458 | // |
| 459 | // A disconnect monitor goroutine runs for the duration of the query. It uses |
| 460 | // bufio.Reader.Peek to detect client disconnects (TCP FIN/RST) while the |
| 461 | // query is in-flight, without consuming any bytes from the stream. When a |
| 462 | // disconnect is detected, the connection context (c.ctx) is cancelled, |
| 463 | // propagating cancellation to gRPC calls on Flight SQL workers. |
| 464 | // |
| 465 | // In child worker processes, the context is also cancelled when the server's |
| 466 | // externalCancelCh is closed (triggered by SIGUSR1 signal). |
| 467 | func (c *clientConn) queryContext() (context.Context, func()) { |
| 468 | return c.queryContextInner(true) |
| 469 | } |