Delay decoding a message's contents in DTFx.AzureStorage #1110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We recently encountered a case where the Azure Functions scale controller was failing to make a scaling decision due to the following error:
As can be seen in the stack trace, this error is thrown when trying to Peek a given queue, which we use to observe the message age amongst other metadata.
The error occurs because, after receiving an azure queue message (of type
CloudQueueMessage
), we wrap it in our own abstraction calledQueueMessage
. When constructing this object, we call theAsString
method ofCloudQueueMessage
, which obtains the message contents, and store them in a class property namedMessage
. This method can throw if the message cannot be decoded, yielding the error above.This is a kind of poison message scenario that can affect the Scale Controller. In the Scale Controller's case, we don't really need to decode the message's contents, as all we need is message and queue metadata such as the average message Age, the number of messages in the queue, and so on.
As a result - this PR moves the call to
AsString
from theCloudQueueMessage
constructor to instead occur in the implementation of it'sMessage
property. This will prevent the ScaleController from error'ing out, as it never needs to access the message's actual contents.As an aside - I meant to write a test for this, but the
CloudQueueMessage
type is sealed, so it cannot be mock'ed, and newer versions of the Azure Storage SDK are more robust against undecodable errors. So I decided against it.