Skip to content

Commit

Permalink
VW: fix MBB token refresh error
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Apr 18, 2022
1 parent bc4545e commit 2cb91bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
9 changes: 4 additions & 5 deletions util/request/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ type roundTripper struct {
base http.RoundTripper
}

const max = 1024 * 64

var (
LogHeaders bool
LogMaxLen = 1024 * 8
reqMetric *prometheus.SummaryVec
resMetric *prometheus.CounterVec
)
Expand Down Expand Up @@ -93,7 +92,7 @@ func dump(r io.ReadCloser, w *strings.Builder) error {
if w.Len() > 0 && len(body) > 0 {
w.WriteString("\n--\n")
}
_, err = w.Write(bytes.TrimSpace(body[:min(max, len(body))]))
_, err = w.Write(bytes.TrimSpace(body[:min(LogMaxLen, len(body))]))
return err
}

Expand All @@ -108,7 +107,7 @@ func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
if LogHeaders {
if body, err := httputil.DumpRequestOut(req, true); err == nil {
bld.WriteString("\n")
bld.Write(bytes.TrimSpace(body[:min(max, len(body))]))
bld.Write(bytes.TrimSpace(body[:min(LogMaxLen, len(body))]))
}
} else {
if save, req.Body, err = drainBody(req.Body); err == nil {
Expand All @@ -130,7 +129,7 @@ func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
if LogHeaders {
if body, err := httputil.DumpResponse(resp, true); err == nil {
bld.WriteString("\n\n")
bld.Write(bytes.TrimSpace(body[:min(max, len(body))]))
bld.Write(bytes.TrimSpace(body[:min(LogMaxLen, len(body))]))
}
} else {
if save, resp.Body, err = drainBody(resp.Body); err == nil {
Expand Down
21 changes: 15 additions & 6 deletions vehicle/vag/tokensource.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,25 @@ func (ts *metaTokenSource) TokenEx() (*Token, error) {
ts.mu.Lock()
defer ts.mu.Unlock()

if ts.ts == nil {
token, err := ts.newT()
if err != nil {
return nil, err
// use token source
if ts.ts != nil {
token, err := ts.ts.TokenEx()
if err == nil {
return token, nil
}
}

ts.ts = ts.newTS(token)
// create new start token
token, err := ts.newT()
if err != nil {
return nil, err
}

token, err := ts.ts.TokenEx()
// create token source
ts.ts = ts.newTS(token)

// use token source
token, err = ts.ts.TokenEx()
if err != nil {
// token source doesn't work anymore, reset it
ts.ts = nil
Expand Down

0 comments on commit 2cb91bd

Please sign in to comment.