瀏覽代碼

Prevent attachment semaphore from blocking permanently

Tulir Asokan 2 年之前
父節點
當前提交
f4284e7b3f
共有 1 個文件被更改,包括 11 次插入3 次删除
  1. 11 3
      attachments.go

+ 11 - 3
attachments.go

@@ -279,10 +279,18 @@ func (br *DiscordBridge) copyAttachmentToMatrix(intent *appservice.IntentAPI, ur
 			}
 
 			const attachmentSizeVal = 1
-			onceErr = br.parallelAttachmentSemaphore.Acquire(context.Background(), attachmentSizeVal)
+			ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+			onceErr = br.parallelAttachmentSemaphore.Acquire(ctx, attachmentSizeVal)
+			cancel()
 			if onceErr != nil {
-				onceErr = fmt.Errorf("failed to acquire semaphore: %w", onceErr)
-				return
+				br.ZLog.Warn().Err(onceErr).Msg("Failed to acquire semaphore")
+				ctx, cancel = context.WithTimeout(context.Background(), 50*time.Second)
+				onceErr = br.parallelAttachmentSemaphore.Acquire(ctx, attachmentSizeVal)
+				cancel()
+				if onceErr != nil {
+					onceErr = fmt.Errorf("reuploading timed out")
+					return
+				}
 			}
 			var semaWg sync.WaitGroup
 			semaWg.Add(1)