(ctx context.Context)
| 284 | } |
| 285 | |
| 286 | func (m *mu) lock(ctx context.Context) error { |
| 287 | select { |
| 288 | case <-m.c.closed: |
| 289 | return net.ErrClosed |
| 290 | case <-ctx.Done(): |
| 291 | return fmt.Errorf("failed to acquire lock: %w", ctx.Err()) |
| 292 | case m.ch <- struct{}{}: |
| 293 | // To make sure the connection is certainly alive. |
| 294 | // As it's possible the send on m.ch was selected |
| 295 | // over the receive on closed. |
| 296 | select { |
| 297 | case <-m.c.closed: |
| 298 | // Make sure to release. |
| 299 | m.unlock() |
| 300 | return net.ErrClosed |
| 301 | default: |
| 302 | } |
| 303 | return nil |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | func (m *mu) unlock() { |
| 308 | select { |
no test coverage detected