()
| 450 | } |
| 451 | |
| 452 | func (m *Manager) Close() error { |
| 453 | m.closeMutex.Lock() |
| 454 | select { |
| 455 | case <-m.closed: |
| 456 | m.closeMutex.Unlock() |
| 457 | return nil |
| 458 | default: |
| 459 | } |
| 460 | close(m.closed) |
| 461 | m.closeCancel() |
| 462 | m.closeMutex.Unlock() |
| 463 | m.closeWait.Wait() |
| 464 | m.mutex.Lock() |
| 465 | defer m.mutex.Unlock() |
| 466 | ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second) |
| 467 | defer cancelFunc() |
| 468 | // nolint:gocritic // Updating a replica is a system function. |
| 469 | _, err := m.db.UpdateReplica(dbauthz.AsSystemRestricted(ctx), database.UpdateReplicaParams{ |
| 470 | ID: m.self.ID, |
| 471 | UpdatedAt: dbtime.Now(), |
| 472 | StartedAt: m.self.StartedAt, |
| 473 | StoppedAt: sql.NullTime{ |
| 474 | Time: dbtime.Now(), |
| 475 | Valid: true, |
| 476 | }, |
| 477 | RelayAddress: m.self.RelayAddress, |
| 478 | RegionID: m.self.RegionID, |
| 479 | Hostname: m.self.Hostname, |
| 480 | Version: m.self.Version, |
| 481 | Error: m.self.Error, |
| 482 | DatabaseLatency: 0, // A stopped replica has no latency. |
| 483 | Primary: false, // A stopped replica cannot be primary. |
| 484 | }) |
| 485 | if err != nil { |
| 486 | return xerrors.Errorf("update replica: %w", err) |
| 487 | } |
| 488 | err = m.pubsub.Publish(PubsubEvent, []byte(m.self.ID.String())) |
| 489 | if err != nil { |
| 490 | return xerrors.Errorf("publish replica update: %w", err) |
| 491 | } |
| 492 | return nil |
| 493 | } |
| 494 | |
| 495 | // CreateDERPMeshTLSConfig creates a TLS configuration for connecting to peers |
| 496 | // in the DERP mesh over private networking. It overrides the ServerName to be |
no test coverage detected