Skip to content

Commit 2a2c0d8

Browse files
route443shawnhankim
authored andcommitted
Fix: ZoneSync delays in some installations caused problems
1 parent 4b975e2 commit 2a2c0d8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

openid_connect.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,25 @@ function retryOriginalRequest(r) {
1212
r.internalRedirect(r.variables.uri + r.variables.is_args + (r.variables.args || ''));
1313
}
1414

15-
function auth(r) {
15+
// If the ID token has not been synced yet, poll the variable every 100ms until
16+
// get a value or after a timeout.
17+
function waitForSessionSync(r, timeLeft) {
18+
if (r.variables.session_jwt) {
19+
retryOriginalRequest(r);
20+
} else if (timeLeft > 0) {
21+
setTimeout(waitForSessionSync, 100, r, timeLeft - 100);
22+
} else {
23+
auth(r, true);
24+
}
25+
}
26+
27+
function auth(r, afterSyncCheck) {
28+
// If a cookie was sent but the ID token is not in the key-value database, wait for the token to be in sync.
29+
if (r.variables.cookie_auth_token && !r.variables.session_jwt && !afterSyncCheck && r.variables.zone_sync_leeway > 0) {
30+
waitForSessionSync(r, r.variables.zone_sync_leeway);
31+
return;
32+
}
33+
1634
if (!r.variables.refresh_token || r.variables.refresh_token == "-") {
1735
newSession = true;
1836

openid_connect_configuration.conf

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ map $host $oidc_hmac_key {
4343
default "ChangeMe";
4444
}
4545

46+
map $host $zone_sync_leeway {
47+
# Specifies the maximum timeout for synchronizing ID tokens between cluster
48+
# nodes when you use shared memory zone content sync. This option is only
49+
# recommended for scenarios where cluster nodes can randomly process
50+
# requests from user agents and there may be a situation where node "A"
51+
# successfully received a token, and node "B" receives the next request in
52+
# less than zone_sync_interval.
53+
default 0; # Time in milliseconds, e.g. (zone_sync_interval * 2 * 1000)
54+
}
55+
4656
map $proto $oidc_cookie_flags {
4757
http "Path=/; SameSite=lax;"; # For HTTP/plaintext testing
4858
https "Path=/; SameSite=lax; HttpOnly; Secure;"; # Production recommendation

0 commit comments

Comments
 (0)