<commit_before>﻿using System;
using System.IO;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using LightningQueues.Exceptions;
using LightningQueues.Logging;
using LightningQueues.Model;
using LightningQueues.Protocol.Chunks;

namespace LightningQueues.Protocol
{
    public class ReceivingProtocol
    {
        // Public for testing
        public static ILogger Logger = LogManager.GetLogger<ReceivingProtocol>();

        public async Task ReadMessagesAsync(string endpoint, Stream stream,
            Func<Message[], IMessageAcceptance> acceptMessages)
        {
            try
            {
                await readMessageAsync(endpoint, stream, acceptMessages).ConfigureAwait(false);
            }
            catch (ObjectDisposedException)
            {
                // Swallowing this so we don't have unobserved task exceptions in the finalizer when we timeout.
            }
        }

        private async Task readMessageAsync(string endpoint, Stream stream, 
            Func<Message[], IMessageAcceptance> acceptMessages)
        {<commit_msg>Handling exceptions after timeout in receive has occurred<commit_after>﻿using System;
using System.IO;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using LightningQueues.Exceptions;
using LightningQueues.Logging;
using LightningQueues.Model;
using LightningQueues.Protocol.Chunks;

namespace LightningQueues.Protocol
{
    public class ReceivingProtocol
    {
        // Public for testing
        public static ILogger Logger = LogManager.GetLogger<ReceivingProtocol>();

        public async Task ReadMessagesAsync(string endpoint, Stream stream,
            Func<Message[], IMessageAcceptance> acceptMessages)
        {
            try
            {
                await readMessageAsync(endpoint, stream, acceptMessages).ConfigureAwait(false);
            }
            catch (ObjectDisposedException)
            {
                // Swallowing this so we don't have unobserved task exceptions in the finalizer when we timeout.
            }
            catch (Exception ex)
            {
                Logger.Error("Error during receive from " + endpoint, ex);
            }
        }

        private async Task readMessageAsync(string endpoint, Stream stream, 
            Func<Message[], IMessageAcceptance> acceptMessages)
        {
{'fraction_non_alphanumeric': 0.06717687074829932, 'fraction_numerical': 0.0, 'mean_word_length': 2.533033033033033, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4257548', 'n_tokens_mistral': 573, 'n_tokens_neox': 551, 'n_words': 158}