From 66d3206d7d59dda02b346cc68ec5e48ee02246b8 Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Tue, 10 Jun 2025 03:54:18 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(channel-test):=20ensure=20pr?= =?UTF-8?q?oper=20state=20reset=20to=20prevent=20deadlocks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/channel-test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/controller/channel-test.go b/controller/channel-test.go index 970c1768..f9c7bf7b 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -271,6 +271,13 @@ func testAllChannels(notify bool) error { disableThreshold = 10000000 // a impossible value } gopool.Go(func() { + // 使用 defer 确保无论如何都会重置运行状态,防止死锁 + defer func() { + testAllChannelsLock.Lock() + testAllChannelsRunning = false + testAllChannelsLock.Unlock() + }() + for _, channel := range channels { isChannelEnabled := channel.Status == common.ChannelStatusEnabled tik := time.Now() @@ -305,9 +312,7 @@ func testAllChannels(notify bool) error { channel.UpdateResponseTime(milliseconds) time.Sleep(common.RequestInterval) } - testAllChannelsLock.Lock() - testAllChannelsRunning = false - testAllChannelsLock.Unlock() + if notify { service.NotifyRootUser(dto.NotifyTypeChannelTest, "通道测试完成", "所有通道测试已完成") }