Add timeout to Tailscale WhoIs call
This commit is contained in:
parent
7a1a654b73
commit
972ff18012
1 changed files with 6 additions and 3 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"tailscale.com/client/tailscale"
|
"tailscale.com/client/tailscale"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -30,8 +31,10 @@ func (ta *TailscaleAuth) Provision(caddy.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ta *TailscaleAuth) Authenticate(wr http.ResponseWriter, req *http.Request) (caddyauth.User, bool, error) {
|
func (ta *TailscaleAuth) Authenticate(_ http.ResponseWriter, req *http.Request) (caddyauth.User, bool, error) {
|
||||||
whois, err := ta.lc.WhoIs(context.Background(), req.RemoteAddr)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
|
||||||
|
defer cancel()
|
||||||
|
whois, err := ta.lc.WhoIs(ctx, req.RemoteAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return caddyauth.User{}, false, err
|
return caddyauth.User{}, false, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue