#payload.create hangs after beforeChange hook completes?

8 messages · Page 1 of 1 (latest)

iron fulcrum
#

Hi! I'm seeing payload.create hang during a specific workflow:

  1. Participation afterChange hook calls initializeProgress server action.
  2. initializeProgress calls payload.create({ collection: 'courseProgress', data: ... }).
  3. CourseProgress has hooks:
// CourseProgress.ts hooks
hooks: {
  beforeChange: [
    async ({ data, operation }) => {
      console.log(`[CourseProgress.beforeChange] Start ${operation}`);
      // ... sync calculations on 'data' ...
      console.log(`[CourseProgress.beforeChange] Finish ${operation}`);
      return data;
    },
  ],
  afterChange: [
    async ({ doc, operation }) => {
      console.log(`[CourseProgress.afterChange] Start ${operation} ID: ${doc.id}`);
      // ... potentially triggers another hook async ...
      console.log(`[CourseProgress.afterChange] Finish ${operation} ID: ${doc.id}`);
      return doc;
    },
  ],
},

Problem: Logs show:

  1. initializeProgress: "Attempting payload.create for courseProgress..."
  2. CourseProgress.beforeChange: Logs "Start create" and "Finish create".
  3. --- HANG --- Execution stops here.

I don't see the log in initializeProgress after the await payload.create(...) line, nor the CourseProgress.afterChange logs immediately.

Why might payload.create hang after beforeChange completes but before afterChange starts? The beforeChange itself has no await calls.

Thanks!

solar drumBOT
thorn falcon
#

Without seeing the actual code this will be a bit tricky to debug

iron fulcrum
#

the beforeChange hooks finishs and gets stuck there

#

when i go to my Neon database and check active queries :

#

insert into "course_progress" ("id", "client_id", "course_id", "participation_id", "status", "percent_complete", "completed_lessons", "total_lessons", "course_type", "last_accessed_at", "completed_at", "passed_at", "certified_at", "exam_score", "updated_at", "created_at") values (default, $1, $2, $3, $4, $5, $6, $7, $8, default, default, default, default, default, $9, default) returning "id", "client_id", "course_id", "participation_id", "status", "percent_complete", "completed_lessons", "total_lessons", "course_type", "last_accessed_at", "completed_at", "passed_at", "certified_at", "exam_score", "updated_at", "created_at"

#

Then After a while it gets terminating Connection :
[error: terminating connection due to idle-in-transaction timeout]