fix: oauth token race in http_transport by burmudar · Pull Request #1269 · sourcegraph/src-cli

Comment on lines 32 to +35

if err := t.refreshToken(ctx); err != nil {
return nil, err
}
token := t.getToken()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very minor: you lock in refresh and in getToken, and this is the only place you call both. Maybe instead you can refactor it to read like this

if err := t.refreshToken(ctx); err != nil {
return nil, err
}
token := t.getToken()
token, err := t.getToken(ctx)
if err != nil {
return nil, err
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I tend to agree. It did feel bit 💩 to do it - only thing that stopped me was getToken does more than what it says, although it's minor in the long run.

I'll update it in a bit.