Sitevision Developer
Log in

Log in

Propagation of session between intertwined apps

As of Sitevision 2022.03.1 there are a new updateSession function to propagate session state between intertwined apps (typically a WebApp that executes a RESTApp via RestAppInvoker).

Published: 2023-03-10  |  Updated: 2023-03-14

The App session state

All WebApps and RESTApps use a shared area of the global session. We commonly refer to this as the "App session" and apps access it via the req.session variable.

This is how it works when an app is executed:

  1. The app starts its execution (of a route)
    • A local mutable copy of the current App session state is made available via the req.session variable.
  2. The app execution finishes
    • The shared App session is updated with current req.session state. I.e. all potential local changes are made available for other apps that will be executed later on.

This is efficient and works really well when apps are executed serially (i.e. the typical page rendering case). But when an app execution involve other apps, this can cause subtle App session state problems - if some or all of the apps mutate req.session. Such typical problem case is when a WebApp executes a RESTApp via RestAppInvoker - and one or both of the apps mutates their req.session.

App session state problems like these can be avoided by using the req.updateSession() function that is introduced in Sitevision 2023.03.1. The function (re-) synchronizes local req.session state with the shared App session state.

Rule of thumb: If your app uses req.session and executes another app - you should consider usage of req.updateSession