Skip to content

Commit

Permalink
[CLIENT-3022] Optimize the ticker
Browse files Browse the repository at this point in the history
  • Loading branch information
khaf committed Jul 17, 2024
1 parent be575a3 commit 399a4e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ To make the library both flexible and fast, we had to integrate the reflection A
<a name="proxy-client--dbaas"></a>
## Proxy Client / DBAAS

To compile the client for the proxy server in out database as a service environment, pass `-tags as_proxy` to the compiler on build.
To compile the client for the proxy server in our database-as-a-service (dbaas) environment, pass `-tags as_proxy` to the compiler on build.

<a name="license"></a>
## License
Expand Down
7 changes: 4 additions & 3 deletions proxy_auth_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ func (interceptor *authInterceptor) tokenRefresher() {

// provide 5 secs of buffer before expiry due to network latency
wait := interceptor.expiry.Sub(time.Now()) - 5*time.Second
ticker := time.NewTicker(wait)
// defer ticker.Close()

for {
ticker := time.NewTicker(wait)
ticker.Reset(wait)
select {
case <-ticker.C:
ticker.Stop() // prevent goroutine leak
err := interceptor.refreshToken()
if err != nil {
wait = time.Second
Expand All @@ -105,7 +107,6 @@ func (interceptor *authInterceptor) tokenRefresher() {
}

case <-interceptor.closer:
ticker.Stop() // prevent goroutine leak
// channel closed; return from the goroutine
return
}
Expand Down

0 comments on commit 399a4e8

Please sign in to comment.