Prevent attachment semaphore from blocking permanently

This commit is contained in:
Tulir Asokan
2023-06-29 15:18:54 +03:00
parent 07785997bf
commit f4284e7b3f

View File

@@ -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)