Skip to content

Introduce access to session state - #1503

Open
lailabougria wants to merge 7 commits into
masterfrom
session-state
Open

lailabougria wants to merge 7 commits into
masterfrom
session-state

Conversation

@lailabougria

Copy link
Copy Markdown
Contributor

No description provided.

using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;

interface ISessionStateStore

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this internal interface? I can only spot a single implementation of it

current.UserState = new UserSessionState
{
ContentType = "application/json",
Type = typeof(T).FullName,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to store this? What's the expected usage?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that this could be emited in observability


current.UserState = new UserSessionState
{
ContentType = "application/json",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Data is defined as JsonElement, can ContentType be anything other than json?

/// <summary>
/// Persists pending session-state changes, if any. Called by the session pump right before the message is completed.
/// </summary>
public async Task Flush(CancellationToken cancellationToken = default)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want have the Save-Flush model enforced in our API?

It seems to be appropriate if the underlying SetSessionStateAsync operations are atomic with the message settlement but currently in our transport they are atomic only when using SendsAtomicWithReceive (default) transaction mode. When using ReceiveOnly, there is no TransactionScope surrounding the ASB API calls and as a result the SetSessionStateAsync is committed separately from Complete/Abandon.

As a result, we might get into some interesting gotachas:

  • With outbox disabled, the session might be updated but the message fails to complete and comes back
  • With outbox enabled, the message might be marked as processed in the outbox but later the Flush might fail and the session state update associated with the message handling is lost

Should we limit the session-state API to the SendsAtomicWithReceive mode (at least in the first release) to avoid these anomalies?

@SzymonPobiega SzymonPobiega left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments. Some are purely esthetic but the comment on the Flash method is more interesting -- documents transactional anomalies that we are exposed to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants