Random null responses for querying existing db entries

System Information
  • Strapi Version: 4.1.12
  • Operating System: mac
  • Database: PostgreSQL
  • Node Version: 16.15.0
  • NPM Version: 8.5.5
  • Yarn Version: 1.22.18


this is my first post here and I hope I’m doing nothing wrong.

Recently I observed a behavior I can’t get a reasonable explanation for:

I have a function in the strapi backend to validate ReadPermissions (see code below). Nothing special here, I would say. This function works and everything is fine.

Now, if I delete an entity in my react-webapp via REST, there are immediately GET requests fired for other entities (because I delete sth → frontend updates → immediately fires some GET Requests). Suddenly my validate function fails, because the “const access” gets null for no (?) reason.

Sometimes its there, but maybe the next or third try, its null again (feels random). It seems like it has sth to do with the simultaneously fired requests. So maybe there is a race between them, and if the delete request is too slow, the DB blocks access (?!). But I just don’t know how to handle this. If there are thousand of users some day, there will be simultaneously requests all the time. Am I missing some critical strapi concepts? How can an existing entity not be found?

I have this behavior in development environment (postgresSQL as docker). In production I don’t want to try :smiley:

P.S. I already logged ctx.state.user and my data.relationX. The data is always there, what makes it even more confusing and random because data.relationX is loaded from the DB as well. Only the access object is null from time to time.

//get data....

const access = await strapi.db
          where: {
            relationX: data.relationX,
            user: ctx.state.user,

//gives null, if DELETE request was slower than (almost) simultaneously GET requests.

 if (no permission) {
      // Error...