fix(web-channel): race condition from visit event #12435
Merged
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.
The visit event today is being intercepted by the web-channel backend; in the handler, we update some user variables using
bp.users.updateAttributes
, which creates a race condition if there is a proactive hook and the flow changes some user variables in an action or an entry node, for example. This isn't easy to reproduce but has been happening for some managed clients, but happens in one of 50 interactions.I could reproduce it by using a puppeteer automated test with a proactive hook + 3 new events sent by the front end simultaneously (events that change the user variable).
What happens is that when the issue occurs, the isSet4 variable gets overwritten by the
bp.users.updateAttributes
call. I was able to fix it by converting the visit message event to a data event and handling the user state update in a hook, this way, the visit event is sent to the event queue and gets executed sequentially.