Skip to content

Commit

Permalink
Log refresh errors
Browse files Browse the repository at this point in the history
  • Loading branch information
s12v committed Jul 30, 2018
1 parent cfe85f0 commit 7af88f2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/square/go-jose"
"golang.org/x/sync/semaphore"
"time"
"log"
)

type JWKSClient interface {
Expand Down Expand Up @@ -57,13 +58,13 @@ func (c *jWKSClient) GetKey(keyId string, use string) (jwk *jose.JSONWebKey, err
val, found := c.cache.Get(keyId)
if found {
entry := val.(*cacheEntry)
if time.Now().After(time.Unix(entry.refresh, 0)) {
if c.sem.TryAcquire(1) {
go func() {
defer c.sem.Release(1)
c.refreshKey(keyId, use)
}()
}
if time.Now().After(time.Unix(entry.refresh, 0)) && c.sem.TryAcquire(1) {
go func() {
defer c.sem.Release(1)
if _, err := c.refreshKey(keyId, use); err != nil {
log.Printf("unable to refresh key: %v", err)
}
}()
}
return entry.jwk, nil
} else {
Expand Down

0 comments on commit 7af88f2

Please sign in to comment.