Commit 47fda99
Add per-issuer lock to prevent thundering herd on new issuers (#180)
This commit addresses the thundering herd problem when multiple threads
simultaneously try to validate tokens from the same issuer:
Per-issuer locking:
- Added a per-issuer mutex map with shared_ptr ownership
- Threads acquire a lock for an issuer before fetching keys from web
- Other threads wait on the lock, then find keys in cache
- Lock ownership transfers through async status for proper lifecycle
- Limited to 1000 cached mutexes to prevent resource exhaustion
Negative caching:
- On web fetch failure (e.g., 404), store empty keys in cache
- Uses same TTL as successful lookups (get_next_update_delta)
- Subsequent lookups hit cache and fail fast without web requests
- Prevents repeated web requests for known-bad issuers
SQLite busy timeout:
- Added 5-second busy timeout to handle concurrent DB access
- Applied to all database operations (init, read, write)
Stress tests:
- StressTestValidToken: 10 threads, 5 seconds, valid token
- StressTestInvalidIssuer: 10 threads, 5 seconds, 404 issuer
- ConcurrentNewIssuerLookup: Verifies only ONE web fetch occurs
Verified behavior:
- Valid issuer: ONE key lookup for thousands of validations
- Invalid issuer: ONE web request (OIDC + OAuth fallback), then cached
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Brian P Bockelman <bockelman@gmail.com>1 parent a569ab5 commit 47fda99
File tree
5 files changed
+718
-19
lines changed- src
- test
5 files changed
+718
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
| |||
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| 34 | + | |
| 35 | + | |
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
| |||
161 | 167 | | |
162 | 168 | | |
163 | 169 | | |
| 170 | + | |
| 171 | + | |
164 | 172 | | |
165 | 173 | | |
166 | 174 | | |
| |||
260 | 268 | | |
261 | 269 | | |
262 | 270 | | |
| 271 | + | |
| 272 | + | |
263 | 273 | | |
264 | 274 | | |
265 | 275 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
37 | 79 | | |
38 | 80 | | |
39 | 81 | | |
| |||
948 | 990 | | |
949 | 991 | | |
950 | 992 | | |
951 | | - | |
| 993 | + | |
952 | 994 | | |
953 | | - | |
954 | 995 | | |
955 | 996 | | |
956 | 997 | | |
957 | 998 | | |
958 | | - | |
959 | | - | |
960 | | - | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
961 | 1023 | | |
962 | 1024 | | |
963 | 1025 | | |
| |||
973 | 1035 | | |
974 | 1036 | | |
975 | 1037 | | |
976 | | - | |
977 | | - | |
978 | | - | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
979 | 1072 | | |
980 | 1073 | | |
981 | 1074 | | |
982 | 1075 | | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
989 | 1081 | | |
990 | 1082 | | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
991 | 1088 | | |
992 | 1089 | | |
993 | 1090 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
555 | 559 | | |
556 | 560 | | |
557 | 561 | | |
| |||
776 | 780 | | |
777 | 781 | | |
778 | 782 | | |
| 783 | + | |
| 784 | + | |
779 | 785 | | |
780 | 786 | | |
781 | 787 | | |
| |||
834 | 840 | | |
835 | 841 | | |
836 | 842 | | |
837 | | - | |
| 843 | + | |
| 844 | + | |
838 | 845 | | |
839 | 846 | | |
840 | 847 | | |
| |||
882 | 889 | | |
883 | 890 | | |
884 | 891 | | |
| 892 | + | |
| 893 | + | |
885 | 894 | | |
886 | 895 | | |
887 | 896 | | |
| |||
893 | 902 | | |
894 | 903 | | |
895 | 904 | | |
896 | | - | |
| 905 | + | |
| 906 | + | |
897 | 907 | | |
898 | 908 | | |
899 | 909 | | |
| |||
1004 | 1014 | | |
1005 | 1015 | | |
1006 | 1016 | | |
| 1017 | + | |
1007 | 1018 | | |
1008 | 1019 | | |
1009 | 1020 | | |
| |||
1181 | 1192 | | |
1182 | 1193 | | |
1183 | 1194 | | |
1184 | | - | |
1185 | | - | |
1186 | | - | |
| 1195 | + | |
| 1196 | + | |
1187 | 1197 | | |
1188 | 1198 | | |
1189 | 1199 | | |
| |||
1195 | 1205 | | |
1196 | 1206 | | |
1197 | 1207 | | |
| 1208 | + | |
1198 | 1209 | | |
1199 | 1210 | | |
| 1211 | + | |
| 1212 | + | |
1200 | 1213 | | |
1201 | 1214 | | |
1202 | 1215 | | |
| |||
0 commit comments