| 243 | } |
| 244 | |
| 245 | func (c *pgCoord) Coordinate( |
| 246 | ctx context.Context, id uuid.UUID, name string, a agpl.CoordinateeAuth, |
| 247 | ) ( |
| 248 | chan<- *proto.CoordinateRequest, <-chan *proto.CoordinateResponse, |
| 249 | ) { |
| 250 | logger := c.logger.With(slog.F("peer_id", id)) |
| 251 | reqs := make(chan *proto.CoordinateRequest, agpl.RequestBufferSize) |
| 252 | resps := make(chan *proto.CoordinateResponse, agpl.ResponseBufferSize) |
| 253 | if !c.querier.isHealthy() { |
| 254 | // If the coordinator is unhealthy, we don't want to hook this Coordinate call up to the |
| 255 | // binder, as that can cause an unnecessary call to DeleteTailnetPeer when the connIO is |
| 256 | // closed. Instead, we just close the response channel and bail out. |
| 257 | // c.f. https://github.com/coder/coder/issues/12923 |
| 258 | c.logger.Info(ctx, "closed incoming coordinate call while unhealthy", |
| 259 | slog.F("peer_id", id), |
| 260 | ) |
| 261 | resps <- &proto.CoordinateResponse{Error: CloseErrUnhealthy} |
| 262 | close(resps) |
| 263 | return reqs, resps |
| 264 | } |
| 265 | cIO := newConnIO(c.ctx, ctx, logger, c.bindings, c.tunnelerCh, c.handshakerCh, reqs, resps, id, name, a) |
| 266 | err := agpl.SendCtx(c.ctx, c.newConnections, cIO) |
| 267 | if err != nil { |
| 268 | // this can only happen if the context is canceled, no need to log |
| 269 | return reqs, resps |
| 270 | } |
| 271 | go func() { |
| 272 | <-cIO.Done() |
| 273 | _ = agpl.SendCtx(c.ctx, c.closeConnections, cIO) |
| 274 | }() |
| 275 | |
| 276 | return reqs, resps |
| 277 | } |
| 278 | |
| 279 | type tKey struct { |
| 280 | src uuid.UUID |