mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: use time.Equal() for external auth token expiry comparison (#22295)
The listen loop in workspaceAgentsExternalAuthListen compared OAuthExpiry using == which compares `time.Time` internal struct fields including the `*time.Location` pointer. `time.LoadLocation` does not cache the returned `*Location` pointer, so each lib/pq connection gets a distinct pointer for the same timezone. When `pq.ParseTimestamp()` applies the connection's location to a parsed timestamp, the resulting time.Time embeds that connection-specific pointer. If the `sql.DB` pool hands out different connections for the two GetExternalAuthLink reads, the identical timestamp produces `time.Time` values where == returns false despite representing the same instant. This is intermittent because the pool _usually_ reuses the same connection for sequential queries. This change uses `.Equal()` to compare instants regardless of location. Also makes the test's validation call counter atomic to fix a possible data race between the HTTP server and test goroutines.
This commit is contained in:
@@ -2045,7 +2045,7 @@ func (api *API) workspaceAgentsExternalAuthListen(ctx context.Context, rw http.R
|
||||
// No point in trying to validate the same token over and over again.
|
||||
if previousToken.OAuthAccessToken == externalAuthLink.OAuthAccessToken &&
|
||||
previousToken.OAuthRefreshToken == externalAuthLink.OAuthRefreshToken &&
|
||||
previousToken.OAuthExpiry == externalAuthLink.OAuthExpiry {
|
||||
previousToken.OAuthExpiry.Equal(externalAuthLink.OAuthExpiry) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user