package telegram

import (
	

	

	

	
	
	
)

func ( *Client) ( int,  error) {
	if errors.Is(, exchange.ErrKeyFingerprintNotFound) {
		.log.Warn(context.Background(), "Resetting cached CDN keys after fingerprint miss",
			log.Int("dc_id", ),
		)
		.cdnKeysMux.Lock()
		.cdnKeys = nil
		.cdnKeysByDC = nil
		.cdnKeysSet = false
		// Bump generation so in-flight help.getCdnConfig results are discarded if
		// they were started before invalidation.
		.cdnKeysGen++
		.cdnKeysMux.Unlock()
		// Drop current singleflight entry so next attempt refetches keys.
		.cdnKeysLoad.Forget(helpGetCDNConfigSingleflightKey)

		// Close asynchronously: callback may be invoked from pool worker
		// goroutine, and synchronous self-close can deadlock on Wait().
		// Queue closes through bounded workers to avoid unbounded goroutine fan-out.
		.cdnPools.invalidateDC()
		// Fingerprint miss is recoverable and handled internally by invalidation
		// + reconnect with fresh keys, no external onDead signal is needed.
		return
	}

	if !errors.Is(, mtproto.ErrPFSDropKeysRequired) {
		// Keep legacy callback semantics for all non-PFS errors.
		if .onDead != nil {
			.onDead()
		}
		return
	}

	.log.Warn(context.Background(), "Dropping stored CDN session key after PFS key reset request",
		log.Int("dc_id", ),
	)
	.sessionsMux.Lock()
	,  := .cdnSessions[]
	if ! {
		 = pool.NewSyncSession(pool.Session{DC: })
		.cdnSessions[] = 
	}
	.Store(pool.Session{DC: })
	.sessionsMux.Unlock()

	if .onDead != nil {
		.onDead()
	}
}