From ed969a1ec985f3aeacba99d742aaf2f09e00cd42 Mon Sep 17 00:00:00 2001 From: tang4595 <137059428@qq.com> Date: Thu, 4 Jul 2024 16:14:32 +0800 Subject: [PATCH] fix: maxed the retry count without the delegate callback --- WuKongIMSDK/Classes/manager/WKRetryManager.m | 37 +++++++++----------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/WuKongIMSDK/Classes/manager/WKRetryManager.m b/WuKongIMSDK/Classes/manager/WKRetryManager.m index 0186aa0..9eaa031 100644 --- a/WuKongIMSDK/Classes/manager/WKRetryManager.m +++ b/WuKongIMSDK/Classes/manager/WKRetryManager.m @@ -365,31 +365,28 @@ -(void) retrySend{ [self.retryLock unlock]; NSTimeInterval now = [[NSDate date] timeIntervalSince1970]; // 如果重试次数小于目标重试次数并且满足重试时间,则重试 - if(item && item.retryCount<[WKSDK shared].options.messageRetryCount) { - if(item.retryCount<[WKSDK shared].options.messageRetryCount ) { - if((now - item.nextRetryTime)>=0) { - if([WKSDK shared].isDebug) { - NSLog(@"重发消息 key:[%@] retryCount: [%ld] nextRetryTime: [%ld]",key,item.retryCount,item.nextRetryTime); - } - item.retryCount++; - item.nextRetryTime =now+[WKSDK shared].options.messageRetryInterval; - [[[WKSDK shared] chatManager] sendMessage:item.message addRetryQueue:false]; + if(!item) continue; + if(item.retryCount<[WKSDK shared].options.messageRetryCount ) { + if((now - item.nextRetryTime)>=0) { + if([WKSDK shared].isDebug) { + NSLog(@"重发消息 key:[%@] retryCount: [%ld] nextRetryTime: [%ld]",key,item.retryCount,item.nextRetryTime); } - }else { // 超过重试次数 消息状态设置为发送失败 - [self.retryLock lock]; - [self.retryDict removeObjectForKey:key]; - [self.retryLock unlock]; - // 更新消息状态为失败 - item.message.status =WK_MESSAGE_FAIL; - [[WKMessageDB shared] updateMessageStatus:WK_MESSAGE_FAIL withClientSeq:item.message.clientSeq]; - - // 通知上层 - [[WKSDK shared].chatManager callMessageUpdateDelegate:item.message]; + item.retryCount++; + item.nextRetryTime =now+[WKSDK shared].options.messageRetryInterval; + [[[WKSDK shared] chatManager] sendMessage:item.message addRetryQueue:false]; } + }else { // 超过重试次数 消息状态设置为发送失败 + [self.retryLock lock]; + [self.retryDict removeObjectForKey:key]; + [self.retryLock unlock]; + // 更新消息状态为失败 + item.message.status =WK_MESSAGE_FAIL; + [[WKMessageDB shared] updateMessageStatus:WK_MESSAGE_FAIL withClientSeq:item.message.clientSeq]; + // 通知上层 + [[WKSDK shared].chatManager callMessageUpdateDelegate:item.message]; } } - } // TODO: retrySend如果执行时间过长 removeRetryItem会出现阻塞情况 (待观察)