Application context, CGI and request context are empty in the futures

Description

Application context, request context and other scopes are empty in the futures. I've created futures with `loadAppContext=true` flag. For instance, `CGI` variables have blank values, `prc` is just empty. So it's hard to make a lot of different methods async.
For example, let's have a method that sends some emails in a loop, each email has a header with a site title that relies on `siteTitle` from the `prc`. If rewrite this loop to async using futures, like this:
```
async
.newFuture(loadAppContext=true)
.allApply(reviews, (review) => reviewService.deliverReview(review, event))
```
it will throw an error because `prc` or `event.getPrivateContext()` is empty inside a `deliverReview` in the future.
Could you please explain what am I doing wrong and maybe there is a solution for such usecase, or is it impossible to use application context in the futures? Thanks!

Activity

Show:
Danil Kravchenko
November 9, 2020, 5:28 PM

I am using a Lucee Server. Thanks for the explanation

Brad Wood
November 9, 2020, 6:30 PM

Yep, that would be the issue. You may be able to pass a hard reference to the event object into your future. I’ll try to revisit this at some point, but basically, the methods Lucee uses to copy the details of a pagecontext into the thread’s pagecontext were not thread safe and would error out a lot under load. I reported this to the Lucee developers and spent hours trying to work around it, but I couldn’t find a solution that was error-free and the Lucee developers never got back to me. This is a deficiency in Lucee.

Danil Kravchenko
November 9, 2020, 7:09 PM

I see. Anyway, thank you for a great work on this. I hope one time Lucee will make pagecontext thread safe and we will be able to use a full power of Futures

Luis Majano
November 10, 2020, 3:01 PM

Like Brad said we have limitations on the Lucee engine to provide us with all we need. However, you can still use hard references, but you will have to pass them into the future’s constructor or via closure references.

Danil Kravchenko
November 10, 2020, 3:51 PM

Thanks for an addition, I’ll try this approach

Assignee

Unassigned

Reporter

Danil Kravchenko

Labels

None

Affects versions

Priority

Major
Configure