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

Commit

Permalink
Handle 404 in Queue.RemoveFirstMessage (#2451)
Browse files Browse the repository at this point in the history
  • Loading branch information
Porges authored Sep 27, 2022
1 parent e6d3b39 commit b3748e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
31 changes: 18 additions & 13 deletions src/ApiService/ApiService/onefuzzlib/Queue.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.Json;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Storage.Queues;
using Azure.Storage.Queues.Models;
Expand All @@ -22,12 +23,11 @@ public interface IQueue {




public class Queue : IQueue {
IStorage _storage;
ILogTracer _log;
readonly IStorage _storage;
readonly ILogTracer _log;

static TimeSpan DEFAULT_DURATION = TimeSpan.FromDays(30);
static readonly TimeSpan DEFAULT_DURATION = TimeSpan.FromDays(30);

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

public async Async.Task<bool> RemoveFirstMessage(string name, StorageType storageType) {
var client = await GetQueueClient(name, storageType);

var msgs = await client.ReceiveMessagesAsync();
foreach (var msg in msgs.Value) {
var resp = await client.DeleteMessageAsync(msg.MessageId, msg.PopReceipt);
if (resp.IsError) {
_log.Error($"failed to delete message from the queue {name} due to {resp.ReasonPhrase}");
return false;
} else {
return true;
try {
var msgs = await client.ReceiveMessagesAsync();
foreach (var msg in msgs.Value) {
var resp = await client.DeleteMessageAsync(msg.MessageId, msg.PopReceipt);
if (resp.IsError) {
_log.Error($"failed to delete message from the queue {name} due to {resp.ReasonPhrase}");
return false;
} else {
return true;
}
}
} catch (RequestFailedException ex) when (ex.Status == 404 || ex.ErrorCode == "QueueNotFound") {
_log.Info($"tried to remove message from queue {name} but it doesn't exist");
return false;
}

return false;
}

Expand Down
1 change: 0 additions & 1 deletion src/ApiService/ApiService/onefuzzlib/ShrinkQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,5 @@ public async Async.Task SetSize(long size) {

public async Async.Task<bool> ShouldShrink() {
return await _queueOps.RemoveFirstMessage(QueueName, StorageType.Config);

}
}

0 comments on commit b3748e4

Please sign in to comment.