@@ -492,7 +492,14 @@ func (c *BSFContext) StartCleanupRoutine() {
492492 for {
493493 select {
494494 case <- c .CleanupTicker .C :
495- c .CleanupExpiredBindings ()
495+ func () {
496+ defer func () {
497+ if r := recover (); r != nil {
498+ logger .CtxLog .Errorf ("Panic in cleanup: %v" , r )
499+ }
500+ }()
501+ c .CleanupExpiredBindings ()
502+ }()
496503 case <- c .ShutdownChannel :
497504 logger .CtxLog .Info ("Stopping PCF binding cleanup routine" )
498505 c .CleanupTicker .Stop ()
@@ -538,7 +545,10 @@ func (c *BSFContext) CleanupExpiredBindings() {
538545
539546 now := time .Now ()
540547 expiredBindings := []string {}
541- inactiveBindings := []string {}
548+ inactiveBindings := []struct {
549+ bindingId string
550+ lastAccessAge time.Duration
551+ }{}
542552
543553 c .mutex .RLock ()
544554 for bindingId , binding := range c .PcfBindings {
@@ -550,7 +560,13 @@ func (c *BSFContext) CleanupExpiredBindings() {
550560
551561 // Check last access time for inactive bindings
552562 if now .Sub (binding .LastAccessTime ) > c .MaxInactiveTime {
553- inactiveBindings = append (inactiveBindings , bindingId )
563+ inactiveBindings = append (inactiveBindings , struct {
564+ bindingId string
565+ lastAccessAge time.Duration
566+ }{
567+ bindingId : bindingId ,
568+ lastAccessAge : now .Sub (binding .LastAccessTime ),
569+ })
554570 }
555571 }
556572 c .mutex .RUnlock ()
@@ -561,11 +577,11 @@ func (c *BSFContext) CleanupExpiredBindings() {
561577 c .DeletePcfBinding (bindingId )
562578 }
563579
564- // Delete inactive bindings
565- for _ , bindingId := range inactiveBindings {
580+ // Delete inactive bindings (logging info captured while lock was held)
581+ for _ , item := range inactiveBindings {
566582 logger .CtxLog .Infof ("Deleting inactive PCF binding: %s (last access: %v ago)" ,
567- bindingId , now . Sub ( c . PcfBindings [ bindingId ]. LastAccessTime ) )
568- c .DeletePcfBinding (bindingId )
583+ item . bindingId , item . lastAccessAge )
584+ c .DeletePcfBinding (item . bindingId )
569585 }
570586
571587 if len (expiredBindings ) > 0 || len (inactiveBindings ) > 0 {
0 commit comments