1
0
mirror of https://github.com/redis/go-redis.git synced 2025-10-18 22:08:50 +03:00

fix nil listener

This commit is contained in:
Nedyalko Dyakov
2025-10-17 14:07:26 +03:00
parent 0e10cd7cd2
commit afba8c285f
4 changed files with 47 additions and 29 deletions

View File

@@ -883,13 +883,35 @@ func (m *mockStreamingProvider) Subscribe(listener auth.CredentialsListener) (au
return nil, nil, m.err
}
if listener == nil {
return nil, nil, errors.New("listener cannot be nil")
}
// Create a done channel to stop the goroutine
done := make(chan struct{})
// Start goroutine to handle updates
go func() {
for creds := range m.updates {
m.mu.Lock()
m.credentials = creds
m.mu.Unlock()
listener.OnNext(creds)
defer func() {
if r := recover(); r != nil {
// this is just a mock:
// allow panics to be caught without crashing
}
}()
for {
select {
case <-done:
return
case creds, ok := <-m.updates:
if !ok {
return
}
m.mu.Lock()
m.credentials = creds
m.mu.Unlock()
listener.OnNext(creds)
}
}
}()
@@ -904,6 +926,7 @@ func (m *mockStreamingProvider) Subscribe(listener auth.CredentialsListener) (au
// allow multiple closes from multiple listeners
}
}()
close(done)
return
}, nil
}