aspnet / WebHooks

[Archived] Libraries to create and consume web hooks on ASP.NET Core. Project moved to https://github.com/aspnet/AspLabs
Apache License 2.0
627 stars 439 forks source link

Messages not being removed from the queue when a webhook uri is invalid #114

Closed pete009 closed 6 years ago

pete009 commented 7 years ago

When a WebHook is added with an invalid Uri (host does not exist etc) by using the noecho feature so that the WebHook uri is not validated, when the WebHookSender sends the message an exception is thrown in AzureWebHookDequeueManager line 281 when waiting for all Tasks to complete. This causes the rest of the code to not be executed. This causes a situation where all messages are resent indefinitely causing duplicate messages to be transmitted.

                   try
                    {
                        Task<HttpResponseMessage> requestTask = _parent._httpClient.SendAsync(request);
                        requestTasks.Add(requestTask);
                    }
                    catch (Exception ex)
                    {
                        string msg = string.Format(CultureInfo.CurrentCulture, AzureStorageResources.DequeueManager_SendFailure, request.RequestUri, ex.Message);
                        Logger.Info(msg);

                        CloudQueueMessage message = GetMessage(workItem);
                        if (DiscardMessage(workItem, message))
                        {
                            deleteMessages.Add(message);
                        }
                    }
                }

                // Wait for all responses and see which messages should be deleted from the queue based on the response statuses.
                HttpResponseMessage[] responses = await Task.WhenAll(requestTasks);

A solution that I have is to remove the Task.WhenAll(requestTasks) and rather to await on the _parent._httpClient.SendAsync(request) to ensure that exceptions while posting are handled in the exception handling block.

Is this the best way of handling the situation? May I submit a pull request for my solution?

HenrikFrystykNielsen commented 7 years ago

That sounds like a great solution! A pull request would be greatly appreciated.

petetheman79 commented 7 years ago

Great, I have raised a pull request. PR #116

dougbu commented 6 years ago

cb46ccaac7