admin管理员组

文章数量:1187304

I am banging my head against the wall trying to debug an inexplicable behavior in my codebase.

I am using Electron 27.3.11.

The following code is just the example I have isolated at the moment.

  async init({ items } = {}) {
    // This logs
    if (Game.config.debug) console.log("[CharacterBase] Initializing...");
    if (!this.skills) this.createSkills();

    // this.talents === null
    if (!this._talents) await this.createTalents("silent");
    if (!this.attributes) this.createAttributes();
    if (!this.subtitle) this.createSubtitle();
    if (!this.doll) this.createDoll();
    if (!this.filepath) this.createFilepath();

    return super.init({ items });
  }

  // ...

  async createTalents(option) {
    // This does not log.
    if (Game.config.debug) console.log("[CharacterBase] Creating talents...");
    this._talents = [];

    for (const key of ["raceObject", "secondaryObject", "tradeObject"])
      for (const k of this[key]?.talents ?? [])
        await this.createTalent(k, option);

    for (const talent of Object.values(Game.TALENTS).filter(
      (talent) => !talent.requirements,
    ))
      await this.createTalent(talent.key, option);

    return this._talents;
  }

All of my code used to run fine. It still runs fine in unit tests. However, it fails to run in process. It fails to run because after an arbitrary amount of code runs, it stops processing promises. As a result, when it hits an await, it hangs forever because the promise never stops pending. In the above code, that happens at await this.createTalents("silent");

I have no idea why this is happening. My code is not even heavy. When I investigate memoryInfo using performance.memory immediately before the hang, I do not have any memory problem. I got:

{
  jsHeapSizeLimit: 3760000000,
  totalJSHeapSize: 68000000,
  usedJSHeapSize: 56800000,
]

The exact point in my code that the hang occurs depends on my code. If I bloat it with console logs or big closures, it hangs on an earlier promise. If I remove console logs, it hangs on a later promise. Yet when it hangs, it never resolves into an out of memory error or anything that might help me understand what is wrong.

I've never encountered anything like this before and I have no idea what to guess is wrong.

本文标签: ElectronChromium stops executing promisesStack Overflow