Parallel functions change the pageContext thread

Description

Not sure how I am getting this error in my thread log.

"ERROR","cfthread-594303","10/25/2020","17:39:59","cfthread-594303","the thread scope cannot be modified from outside the owner thread;the thread scope cannot be modified from outside the owner thread;lucee.runtime.exp.ApplicationException: the thread scope cannot be modified from outside the owner

thread
at lucee.runtime.thread.ThreadsImpl.errorOutside(ThreadsImpl.java:395)
at lucee.runtime.thread.ThreadsImpl.set(ThreadsImpl.java:271)
at lucee.runtime.type.util.StructSupport.set(StructSupport.java:262)
at lucee.runtime.util.VariableUtilImpl.set(VariableUtilImpl.java:424)
at lucee.runtime.PageContextImpl.set(PageContextImpl.java:1458)
at bay.s3_cfc$cf$133.threadCall(/bay/s3.cfc:163)
at lucee.runtime.thread.ChildThreadImpl.execute(ChildThreadImpl.java:203)
at lucee.runtime.thread.ChildThreadImpl.run(ChildThreadImpl.java:145)
"

line 163 = thread.result = local.s3.putObject(bucket=attributes.bucket, objectkey=attributes.path_to_resource, filecontent=local.body, contenttype=local.contentType);

function upload(resource, file, string contents = '', boolean waitForComplete = true){
if(IsSimpleValue(arguments.file)){
local.files = [arguments.file];
}

if(IsArray(arguments.file)){
local.files = Duplicate(arguments.file);
}

local.ret = StructNew();

local.threads = StructNew();

local.parse = parseResource(arguments.resource);

local.p_endpoint = local.parse.endpoint;
local.p_bucket = local.parse.bucket;
local.p_resource = local.parse.resource;

for(local.file in local.files){
local.threadname = 'thread_' & replace(createUUID(), '-', '', 'ALL');

local.threads[local.threadname] = local.file;

if(local.file contains '/'){
local.path_to_resource = '#local.p_resource#/#listlast(local.file, "/")#';
}else{
local.path_to_resource = '#local.p_resource#/#listlast(local.file, "\")#';
}

thread action="run", name="#local.threadname#", file="#local.file#", endpoint="#local.p_endpoint#", path_to_resource="#local.path_to_resource#", bucket="#local.p_bucket#", contents="#arguments.contents#" {
if(left(attributes.file, 4) eq 'http'){
http result="local.GET", method="GET", url="#attributes.file#", getasbinary="yes" {}

local.body = local.GET.filecontent;
}else{
if(attributes.contents eq ''){
local.body = fileReadBinary(attributes.file);
}else{
local.body = attributes.contents;
}
}

local.s3 = this.aws[attributes.endpoint].s3;

thread.attributes = attributes;

switch(listLast(attributes.path_to_resource, '.')){
case 'jpg':
local.contentType = 'image/jpeg';

break;

case 'gif':
local.contentType = 'image/gif';

break;

case 'png':
local.contentType = 'image/png';

break;

case 'pdf':
local.contentType = 'application/pdf';

break;

case 'html':
local.contentType = 'text/html';

break;

default:
local.contentType = '';

break;
}

thread.result = local.s3.putObject(bucket=attributes.bucket, objectkey=attributes.path_to_resource, filecontent=local.body, contenttype=local.contentType);

thread.status_code = thread.result.statusCode;
}
}

if(arguments.waitForComplete){
threadJoin(StructKeyList(local.threads));

for(local.thread in local.threads){
local.ret[local.threads[local.thread]] = evaluate(local.thread);
}

return local.ret;
}else{
return true;
}
}

Environment

None

Attachments

4

Activity

Show:

Zac Spitzer 10 March 2025 at 12:29

even simpler

Zac Spitzer 10 March 2025 at 11:43
Edited

the problem is that arrayEach() isn’t resetting the thread?

before arrayEach: cfthread-1

post arrayEach: pool-6-thread-1 should be cfthread-1

Adam Cameron 7 December 2023 at 12:58

See my comment @ .

This is not just a “nested threads” thing. Our situation is more like the situation in LDEV-1389, and still exists in 5.3.9.173.

I think whatever the situation was there, it wasn’t fixed thoroughly / only treated a symptom, not the cause.

One thing I can confirm though is we have a <cfhttp> call in the mix in our case, so there’s some commonality with there. Does <cfhttp> do some threading stuff of its own internally, that is interfering?

Zac Spitzer 30 May 2023 at 20:39

Zac Spitzer 30 May 2023 at 19:46
Edited

simple repo

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Sprint

Affects versions

Created 26 October 2020 at 04:24
Updated last week