|
@@ -283,6 +283,22 @@ public class MediaAuthServiceImpl implements MediaAuthService {
|
|
|
long[] existing = processedAuthCodes.putIfAbsent(key, processing);
|
|
long[] existing = processedAuthCodes.putIfAbsent(key, processing);
|
|
|
if (existing != null) {
|
|
if (existing != null) {
|
|
|
if (existing[1] == PROCESSING) {
|
|
if (existing[1] == PROCESSING) {
|
|
|
|
|
+ // 浏览器/网关可能因首次处理超时而重发同一回调,这里等待首个请求完成并复用其结果
|
|
|
|
|
+ long deadline = System.currentTimeMillis() + 15_000L;
|
|
|
|
|
+ long[] done = existing;
|
|
|
|
|
+ while (done != null && done[1] == PROCESSING && System.currentTimeMillis() < deadline) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.sleep(500L);
|
|
|
|
|
+ } catch (InterruptedException ie) {
|
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ done = processedAuthCodes.get(key);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (done != null && done[1] != PROCESSING && done[1] > 0) {
|
|
|
|
|
+ log.info("{} authorization callback duplicated, return first result after waiting, authCode={}", media.getName(), authCode);
|
|
|
|
|
+ return done[0];
|
|
|
|
|
+ }
|
|
|
throw new BusinessException(429, media.getName() + "授权回调处理中,请稍后重试");
|
|
throw new BusinessException(429, media.getName() + "授权回调处理中,请稍后重试");
|
|
|
}
|
|
}
|
|
|
if (System.currentTimeMillis() - existing[1] < PROCESSED_TTL_MS) {
|
|
if (System.currentTimeMillis() - existing[1] < PROCESSED_TTL_MS) {
|