-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Closed
Labels
status: needs-triagePossible bug which hasn't been reproduced yetPossible bug which hasn't been reproduced yet
Description
Link to reproduction
No response
Describe the Bug
Apologies if this is expected behavior, my grasp of sync/async node is not stellar but this does smell a bit funny to me. I'm finding that if an afterChange hook does a lot of long running nonblocking work (in my case it's a few thousand record updates), it still blocks admin completing and generally leads to a timeout.
To Reproduce
Create the below collection and save a record, you'll see that the record itself is immediately created but then admin is stuck on the "loading" screen indefinitely and eventually times out.
const Sandbox = {
slug: 'sandbox',
fields: [
{
name: 'name',
type: 'text',
hooks: {
afterChange: [
async (args) => {
console.log(`Starting after change hook`);
// Do 2000 payload writes but don't await them
for (let i = 0; i < 2000; i++) {
args.req.payload.create({
collection: 'sandbox',
data: { name: `name ${Math.random()}` },
});
}
console.log(`Ending after change hook`);
},
],
},
},
],
};
export default Sandbox;
Payload Version
2.7.0
Adapters and Plugins
db-mongodb
Metadata
Metadata
Assignees
Labels
status: needs-triagePossible bug which hasn't been reproduced yetPossible bug which hasn't been reproduced yet