Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 64c9440

Browse files
committed
Handle 404 in Queue.RemoveFirstMessage (#2451)
1 parent 85fca0d commit 64c9440

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/ApiService/ApiService/onefuzzlib/Queue.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text.Json;
22
using System.Threading.Tasks;
3+
using Azure;
34
using Azure.Core;
45
using Azure.Storage.Queues;
56
using Azure.Storage.Queues.Models;
@@ -22,12 +23,11 @@ public interface IQueue {
2223

2324

2425

25-
2626
public class Queue : IQueue {
27-
IStorage _storage;
28-
ILogTracer _log;
27+
readonly IStorage _storage;
28+
readonly ILogTracer _log;
2929

30-
static TimeSpan DEFAULT_DURATION = TimeSpan.FromDays(30);
30+
static readonly TimeSpan DEFAULT_DURATION = TimeSpan.FromDays(30);
3131

3232
public Queue(IStorage storage, ILogTracer log) {
3333
_storage = storage;
@@ -110,17 +110,22 @@ public async Async.Task ClearQueue(string name, StorageType storageType) {
110110

111111
public async Async.Task<bool> RemoveFirstMessage(string name, StorageType storageType) {
112112
var client = await GetQueueClient(name, storageType);
113-
114-
var msgs = await client.ReceiveMessagesAsync();
115-
foreach (var msg in msgs.Value) {
116-
var resp = await client.DeleteMessageAsync(msg.MessageId, msg.PopReceipt);
117-
if (resp.IsError) {
118-
_log.Error($"failed to delete message from the queue {name} due to {resp.ReasonPhrase}");
119-
return false;
120-
} else {
121-
return true;
113+
try {
114+
var msgs = await client.ReceiveMessagesAsync();
115+
foreach (var msg in msgs.Value) {
116+
var resp = await client.DeleteMessageAsync(msg.MessageId, msg.PopReceipt);
117+
if (resp.IsError) {
118+
_log.Error($"failed to delete message from the queue {name} due to {resp.ReasonPhrase}");
119+
return false;
120+
} else {
121+
return true;
122+
}
122123
}
124+
} catch (RequestFailedException ex) when (ex.Status == 404 || ex.ErrorCode == "QueueNotFound") {
125+
_log.Info($"tried to remove message from queue {name} but it doesn't exist");
126+
return false;
123127
}
128+
124129
return false;
125130
}
126131

src/ApiService/ApiService/onefuzzlib/ShrinkQueue.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,5 @@ public async Async.Task SetSize(long size) {
5858

5959
public async Async.Task<bool> ShouldShrink() {
6060
return await _queueOps.RemoveFirstMessage(QueueName, StorageType.Config);
61-
6261
}
6362
}

0 commit comments

Comments
 (0)