Event Hub Stream Provider exception (when EH partition is moved ? )
We've started to see this exception in our logs and can't understand what it actually means and why it manifested itself after a minor deployment
[2017-06-01 03:29:25.020 GMT 23 ERROR 103328 PullingAgentSystemTarget/FF/b7b682b4-BullclipEventHub 100.73.86.45:11111] !!!!!!!!!! Exception while reading from queue.
Exc level 0: Microsoft.ServiceBus.Messaging.MessagingCommunicationException: No connection handler was found for virtual host 'bullclip-production.servicebus.windows.net:15168'. Remote container id is 'a76f3594b2e34a51b3ba23d602e016d8'. TrackingId:1563685fced940d28dc201a13b5e8da5_B6_B6, SystemTracker:SharedConnectionListener, Timestamp:6/1/2017 3:29:25 AM
at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
at Microsoft.ServiceBus.Messaging.MessageReceiver.RetryReceiveEventDataAsyncResult.TryReceiveEnd(IAsyncResult r, IEnumerable`1& messages)
at Microsoft.ServiceBus.Messaging.MessageReceiver.EndTryReceiveEventData(IAsyncResult result, IEnumerable`1& messages)
at Microsoft.ServiceBus.Messaging.EventHubReceiver.<ReceiveAsync>b__56_1(IAsyncResult result)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Orleans.ServiceBus.Providers.EventHubAdapterReceiver.<GetQueueMessagesAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Orleans.Streams.PersistentStreamPullingAgent.<ReadFromQueue>d__35.MoveNext()
and along with it goes this one sometimes:
Orleans.Streams.QueueCacheMissException: Item not found in cache. Requested: EventHubSequenceToken(EventHubOffset: 4302746296, SequenceNumber: 5470, EventIndex: 0), Low: [EventSequenceToken: SeqNum=5472, EventIndex=0], High: [EventSequenceToken: SeqNum=5472, EventIndex=0]
at Orleans.Providers.Streams.Common.PooledQueueCache`2.SetCursor(Cursor cursor, StreamSequenceToken sequenceToken)
at Orleans.ServiceBus.Providers.EventHubQueueCache`1.GetCursor(IStreamIdentity streamIdentity, StreamSequenceToken sequenceToken)
at Orleans.ServiceBus.Providers.EventHubAdapterReceiver.GetCacheCursor(IStreamIdentity streamIdentity, StreamSequenceToken token)
at Orleans.Streams.PersistentStreamPullingAgent.<DoHandshakeWithConsumer>d__31.MoveNext()
I found this SO question with the similar exception
Could it be related? We have 2 30 mins periods of these exceptions... Does stream implementation handle such partition moves and reconnections well ?
I think those are two different issues.
For the first issue. Orleans streaming will spin up one agent for per partition, and the pulling agent uses native EventHubReceiver to pull messages from the partition. The handling on such partition moves and reconnections is the same as native EventHubReceiver. I don't think we have extra handing on those. So I believe the cause for the first exception is the same as the one in SO.
Although I don't know why it starts to happen after this minor deployment.. what version are you guys on?
For the second issue, CacheMissException often is thrown when the consumer is trying to read an item which is not in the cache anymore. There's couple routes which can lead to this.
- non-optimal configuration on EventHubStreamProviderSettings.DataMinTimeInCache, and DataMaxAgeInCacheName. Since cache's purging logic depends on those two. If you configure it to be too small, it will increase the possibility of consumer trying to access an item in the cache which is already purged.
- A low traffic queue share blockPool with many high traffic queues if you are using Orleans with a version prior to 1.5 beta. Since when a blockPool reach its configured maxSize , it will trigger purging the oldest block to free up space, no matter it should be purged by time based purge or not. You will more likely to see CacheMissException in the low traffic queue in above scenario. But it can happen in all scenario. This is a bug which is fixed in 1.5beta.
- There's poison events in your queue and your consumer grain has retry logic on event processing failure. So if this consumer grain keep trying to process the same event, eventually this event will not be in the cache anymore due to time based purge
But those are all my guessing, I think provide me more info will help. What's the difference between those two deployment? Do you guys has config change, change on partition traffic?
We have 2 30 mins periods of these exceptions...
do you mean you see those two exceptions every 30 mins?
What version of Orleans are you using?
As Xiazen stated, MessagingCommunicationException is an event hub error. It should be transient, benign and independent of deployment.
The cache miss can cause data loss. Since it's occurring during "DoHandshakeWithConsumer", which is done only when the agent is preparing to deliver events to a consumer, this is most likely due to the sequence token passed to subscribe (or resume) by the consumer being too old. The events related to that token have already been purged from the cache. If this is the case, as xianzen said, you may need to configure a bigger cache, a longer data min time in cache, or increase how often the grains stores sequence tokens.
We are still on 1.3.1 on Production. Upgrade experience to 1.4 is very painful but we are slowly getting there :).

☝️ This what I mean by having 30 mins blocks of exceptions. They start with no reason, being thrown for 2 mins, then stops for roughly about 30-40 mins. Then start again. I thought that we stopped it yesterday after rebooting but it re-appeared today..
Configuration keys and examples are very appreciated, as there is no docs on event hub. These settings are not very obvious from consumers perspective...
With regards to cache miss exception - ok, got it, it looks connected as they appeared one next to another in our yesterday logs, but correlation != causation 😃 . We don't have any streams that are sharing same EH queues, we send only annotations through event hub (although we thought about switching other streams to EH).
@jason-bragg data loss is bad... and we are not storing checkpoints because of the bug in 1.3 and it looks like it wasn't fixed in 1.4.1, cause on our test deployment - we still have reports of that full day annotations replay, as described in #2935 (we don't have 2 clusters running in parallel, for test we have in place upgrades but even on v1.4.1 with startFromNow:false it's doing the replay, not using the checkpointers.
What also interesting with regards to first error is that Azure Event Hub logs show that there were no messages around 9:37am mark (when the last block started, first EH messages were around 9:52) and the 8:55 peak is not exactly correlating with exceptions

We ran a test on production - this doesn't affect our sync functionality, so it's less critical than it may look like. Also another question - is that expected to have outgoing messages count is exactly 2x as incoming ? Is this because each silo instance reads all the data from $default consumer group ? So there is no coordination between readers and if we will run 5x instances - for every 1000 incoming messages there will be 5000 outgoing messages, is this right ?
I think you are correct if I understand you correctly. So every stream can have multiple consumer and producer. So if a stream has 5 consumer and one producer, then the same message in the stream will be delivering to this 5 consumer, assuming their progress in the stream are similar, meaning their sequence token, which they hand in when subscribe/resume, is before this message. So the out-going messages(messages delivered) will be roughly 5 times of the incoming
It's good to know this is less critical than it may look. 💃 I feel happy for you and us .
But getting cache miss means potential data loss, why is this not affecting your sync functionality? Or do yo have a clue on how to fix it?
Last, I'm not sure what I'm looking at in the graph. what's the lighter blue line and the blue line. Lighter blue is the exception count? blue line is the message count? if this is correct, then I think there's a correlation between this two right?
Upgrade experience to 1.4 is very painful.
Understood, though we're about to release 1.4.2, so if upgrade isn't complete I'd consider using that.
We are not storing checkpoints because of the bug in 1.3 and it looks like it wasn't fixed in 1.4.1
It has been addressed by 1.4.1, so if checkpoints are still not being stored correctly in the upgraded version, we need investigate. I can also help you with a work around for this, if that helps.
Is that expected to have outgoing messages count is exactly 2x as incoming ? Is this because each silo instance reads all the data from $default consumer group ? So there is no coordination between readers and if we will run 5x instances - for every 1000 incoming messages there will be 5000 outgoing messages, is this right ?
No. This depends on what you're measuring. If you're using EventHubs performance counters to track messages written to Eventhub and read from EventHub, those should be the same, but if you're measuring how many events were processed by grains, as @xiazen stated, this can be effected by the number of consumers on a stream. If all streams have 5 consumers, the events processed will be 5x the number produced. In either case, this should be independent of how many silos are in the cluster. Per silo numbers will change based off the number of silos, but numbers per cluster should be deterministic.
@centur, let's focus on the cache miss, as that indicates data loss. Do you see any patterns to the cache miss exceptions? Are you seeing the cache miss in 30 minute intervals? Do they only occur during deployment?
we are about to release 1.4.2 early next week with couple more bug fixes btw. If you are upgrading to 1.4 and not finished yet, highly recommended push the version number a bit higher ~
Upgrade is not yet complete. Well we are running it for an about a week in dev\test envs to see what new errors it may throw in our logs. So we will upgrade to 1.4.2 once it will be available.
@jason-bragg the second screen snippet is from Azure Portal UI - it shows incoming and outgoing messages of a hub in question. Somehow outgoing are always x2 of incoming counter. It's not from orleans internal statistics as @xiazen wrote. Although I don't know how reliable EH own statistics, I would assume it's correct. This means each message was read twice from EH. I understand that internally each message multiplied by number of subscribers, but from my understanding it should be read once, not twice.
I will start another issue for cache miss to separate the discussions, would be easier to have 2 threads and as these issues are not related - they can be closed separately. Lets keep this for EHub discussion. I don't know how to fix it yet and I don't know how it affects our functionality. I meant that the main exception for this issue - an error with this message:
No connection handler was found for virtual host 'bullclip-production.servicebus.windows.net:15168'. Remote container id is 'a76f3594b2e34a51b3ba23d602e016d8'. TrackingId:1563685fced940d28dc201a13b5e8da5_B6_B6, SystemTracker:SharedConnectionListener, Timestamp:6/1/2017 3:29:25 AM
does not affect our sync functionality, despite it happens pretty often.
Cache miss may affect us, but on our clients we have some redundancy that silently retries annotations if they failed to be confirmed on first attempt, so I suppose it saves us here and there is no visual miss that would raise customer questions. Although I can admit we have some strange behaviour in this area that we are going to investigate.
@xiazen with regards to what you're looking at on that second screen snippet : this is an output of Metrics from Azure portal. light blue is Incoming messages counter, dark blue is outgoing messages counter. Here is a bigger snippet over longer period from our dev environment with full legend.

And it's sill not clear why outgoing are so much bigger than incoming, but these are from 5 different hubs in the same namespace and some of these messages read from the beginning of the $default group few times. So I'd assume these numbers are not very reliable. Although prev diagram is from short period of production and there is no other parasite readers for that namespace. and it shows double reads over writes, which is strange...
I pulled down Orleans 1.3 and did see anything which would cause outgoing messages to be twice as incoming messages for eventhub, which is strange since it doesn't match with your graph..
Is Orleans streaming the only consumer for your eventhub?
And also, can you do me a favor, instead of comparing incoming messages with outgoing messages, can you compare incoming bytes with outgoing bytes in your production env? Since I don't know how eventhub team count their message count, maybe bytes is the more universal metric here. Both incoming bytes and out going bytes are in the metric list in the snippet you showed me.

It's doubled too
One thing I'm not sure I understand in full (and this may be what confuses us here). We have 1 namespace and 2 hubs there prod and pre-prod. Both hubs are using $Default consumer group in the hubs.
I can see in configuration that prod and pre-prod envs are using different hubs. And we don't have much activity on pre-prod really. But could it be that pre-prod hub somehow pulls out all the same messages from prod hub and thus doubling our read statistics somehow ?
This is strange. I will try reproduce it based on the information I got currently.
But could it be that pre-prod hub somehow pulls out all the same messages from prod hub and thus doubling our read statistics somehow?
Only if it were misconfigured with both stream providers eventhub settings being the same. Not likely, but not impossible. Probably worth double checking your configuration.
I reproduced the doubling issue in our side. I still couldn't find the cause in our side. But it seems that it is related to the fact we are using eventhub batch reading, based on this issue I found on GitHub: https://github.com/Azure/azure-webjobs-sdk/issues/890
@jason-bragg I checked it few times, all environments are using their unique connections and hubs. As @xiazen reproduced the issue and linked it to azure webjobs - I think the message doubling is not Orleans issue.