From 8edc07199763ab1bec035dc8e411ab2728728a91 Mon Sep 17 00:00:00 2001 From: testadmin Date: Tue, 19 May 2026 14:25:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=80=92=E8=AE=A1=E6=97=B6=E5=8D=A1?= =?UTF-8?q?=E4=BD=8F=E6=A0=B9=E5=9B=A0=E4=BF=AE=E5=A4=8D=20=E2=80=94=20Red?= =?UTF-8?q?is=20TTL=E7=BC=93=E5=86=B2+=E5=89=8D=E7=AB=AFwatchdog=E5=85=9C?= =?UTF-8?q?=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:CountdownService用while(sleep(1))阻塞循环推送倒计时, Redis key TTL=wait_time,3台同时运行时worker争用导致循环慢于 Redis过期时间,key先过期→循环中断→倒计时冻结在当前秒数。 修复: 1. Redis TTL加10秒缓冲(waitTime+10),防止key提前过期 2. 前端加watchdog兜底:服务端2秒没推送就本地继续倒计时 --- app/services/process/CountdownService.php | 2 +- public/static/handle/js/handle.js | 12 ++++++++++++ public/static/handle/js/handle_b.js | 12 ++++++++++++ public/static/handle/js/handle_b_sb.js | 12 ++++++++++++ public/static/handle/js/handle_b_sb_scan_four.js | 12 ++++++++++++ public/static/handle/js/handle_dice.js | 12 ++++++++++++ public/static/handle/js/handle_dt_sb.js | 12 ++++++++++++ public/static/handle/js/handle_nn_sb.js | 12 ++++++++++++ public/static/handle/js/handle_roulette.js | 12 ++++++++++++ 9 files changed, 97 insertions(+), 1 deletion(-) diff --git a/app/services/process/CountdownService.php b/app/services/process/CountdownService.php index f40b387..c31158a 100644 --- a/app/services/process/CountdownService.php +++ b/app/services/process/CountdownService.php @@ -27,7 +27,7 @@ class CountdownService //处理倒计时 $waitTime = intval($tableInfo['wait_time']); //将倒计时用作是redis的过期时间 - RedisUtil::save('countdown_'.$numberTabInfo['id'],$waitTime,$waitTime); + RedisUtil::save('countdown_'.$numberTabInfo['id'],$waitTime,$waitTime + 10); while($waitTime >= 0){ $countdown = Cache::store('redis')->get('countdown_'.$numberTabInfo['id']); if ($countdown){ diff --git a/public/static/handle/js/handle.js b/public/static/handle/js/handle.js index d8fd56c..c59158a 100644 --- a/public/static/handle/js/handle.js +++ b/public/static/handle/js/handle.js @@ -532,9 +532,21 @@ websocket.on('resetBoot',function(data){ } } }); +var _cdTimer = null; +var _cdVal = 0; websocket.on('startBetCountDown',function(data){ if(data.status == true && data.table_id == table_id){ + _cdVal = data.count_down; countDown(data.count_down); + if(_cdTimer) clearTimeout(_cdTimer); + if(_cdVal > 0){ + _cdTimer = setTimeout(function _tick(){ + _cdVal--; + if(_cdVal >= 0) countDown(_cdVal); + if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000); + else _cdTimer = null; + }, 2000); + } } }); websocket.on('endBet',function(data){ diff --git a/public/static/handle/js/handle_b.js b/public/static/handle/js/handle_b.js index ae5436d..cb71bf7 100644 --- a/public/static/handle/js/handle_b.js +++ b/public/static/handle/js/handle_b.js @@ -259,9 +259,21 @@ websocket.on('resetBoot',function(data){ layer.msg(lang[data.msg]); } }); +var _cdTimer = null; +var _cdVal = 0; websocket.on('startBetCountDown',function(data){ if(data.status == true && data.table_id == table_id){ + _cdVal = data.count_down; countDown(data.count_down); + if(_cdTimer) clearTimeout(_cdTimer); + if(_cdVal > 0){ + _cdTimer = setTimeout(function _tick(){ + _cdVal--; + if(_cdVal >= 0) countDown(_cdVal); + if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000); + else _cdTimer = null; + }, 2000); + } } }); websocket.on('endBet',function(data){ diff --git a/public/static/handle/js/handle_b_sb.js b/public/static/handle/js/handle_b_sb.js index 661d428..b4acc2c 100644 --- a/public/static/handle/js/handle_b_sb.js +++ b/public/static/handle/js/handle_b_sb.js @@ -504,9 +504,21 @@ websocket.on('resetBoot',function(data){ } } }); +var _cdTimer = null; +var _cdVal = 0; websocket.on('startBetCountDown',function(data){ if(data.status == true && data.table_id == table_id){ + _cdVal = data.count_down; countDown(data.count_down); + if(_cdTimer) clearTimeout(_cdTimer); + if(_cdVal > 0){ + _cdTimer = setTimeout(function _tick(){ + _cdVal--; + if(_cdVal >= 0) countDown(_cdVal); + if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000); + else _cdTimer = null; + }, 2000); + } } }); websocket.on('endBet',function(data){ diff --git a/public/static/handle/js/handle_b_sb_scan_four.js b/public/static/handle/js/handle_b_sb_scan_four.js index 6e31a69..8458067 100644 --- a/public/static/handle/js/handle_b_sb_scan_four.js +++ b/public/static/handle/js/handle_b_sb_scan_four.js @@ -520,9 +520,21 @@ websocket.on('resetBoot',function(data){ } } }); +var _cdTimer = null; +var _cdVal = 0; websocket.on('startBetCountDown',function(data){ if(data.status == true && data.table_id == table_id){ + _cdVal = data.count_down; countDown(data.count_down); + if(_cdTimer) clearTimeout(_cdTimer); + if(_cdVal > 0){ + _cdTimer = setTimeout(function _tick(){ + _cdVal--; + if(_cdVal >= 0) countDown(_cdVal); + if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000); + else _cdTimer = null; + }, 2000); + } } }); websocket.on('endBet',function(data){ diff --git a/public/static/handle/js/handle_dice.js b/public/static/handle/js/handle_dice.js index 2439a89..942d6ba 100644 --- a/public/static/handle/js/handle_dice.js +++ b/public/static/handle/js/handle_dice.js @@ -197,9 +197,21 @@ websocket.on('resetBoot',function(data){ } } }); +var _cdTimer = null; +var _cdVal = 0; websocket.on('startBetCountDown',function(data){ if(data.status == true && data.table_id == table_id){ + _cdVal = data.count_down; countDown(data.count_down); + if(_cdTimer) clearTimeout(_cdTimer); + if(_cdVal > 0){ + _cdTimer = setTimeout(function _tick(){ + _cdVal--; + if(_cdVal >= 0) countDown(_cdVal); + if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000); + else _cdTimer = null; + }, 2000); + } } }); websocket.on('endBet',function(data){ diff --git a/public/static/handle/js/handle_dt_sb.js b/public/static/handle/js/handle_dt_sb.js index 7d77777..e741375 100644 --- a/public/static/handle/js/handle_dt_sb.js +++ b/public/static/handle/js/handle_dt_sb.js @@ -495,9 +495,21 @@ websocket.on('resetBoot',function(data){ } } }); +var _cdTimer = null; +var _cdVal = 0; websocket.on('startBetCountDown',function(data){ if(data.status == true && data.table_id == table_id){ + _cdVal = data.count_down; countDown(data.count_down); + if(_cdTimer) clearTimeout(_cdTimer); + if(_cdVal > 0){ + _cdTimer = setTimeout(function _tick(){ + _cdVal--; + if(_cdVal >= 0) countDown(_cdVal); + if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000); + else _cdTimer = null; + }, 2000); + } } }); websocket.on('endBet',function(data){ diff --git a/public/static/handle/js/handle_nn_sb.js b/public/static/handle/js/handle_nn_sb.js index dda2001..8ca0818 100644 --- a/public/static/handle/js/handle_nn_sb.js +++ b/public/static/handle/js/handle_nn_sb.js @@ -565,9 +565,21 @@ websocket.on('resetBoot',function(data){ } } }); +var _cdTimer = null; +var _cdVal = 0; websocket.on('startBetCountDown',function(data){ if(data.status == true && data.table_id == table_id){ + _cdVal = data.count_down; countDown(data.count_down); + if(_cdTimer) clearTimeout(_cdTimer); + if(_cdVal > 0){ + _cdTimer = setTimeout(function _tick(){ + _cdVal--; + if(_cdVal >= 0) countDown(_cdVal); + if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000); + else _cdTimer = null; + }, 2000); + } } }); websocket.on('endBet',function(data){ diff --git a/public/static/handle/js/handle_roulette.js b/public/static/handle/js/handle_roulette.js index 4ee15c6..f77c656 100644 --- a/public/static/handle/js/handle_roulette.js +++ b/public/static/handle/js/handle_roulette.js @@ -177,9 +177,21 @@ websocket.on('resetBoot',function(data){ } } }); +var _cdTimer = null; +var _cdVal = 0; websocket.on('startBetCountDown',function(data){ if(data.status == true && data.table_id == table_id){ + _cdVal = data.count_down; countDown(data.count_down); + if(_cdTimer) clearTimeout(_cdTimer); + if(_cdVal > 0){ + _cdTimer = setTimeout(function _tick(){ + _cdVal--; + if(_cdVal >= 0) countDown(_cdVal); + if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000); + else _cdTimer = null; + }, 2000); + } } }); websocket.on('endBet',function(data){