cts icon indicating copy to clipboard operation
cts copied to clipboard

Ensure devicePool.release is called for both providers even if one rejects

Open greggman opened this issue 11 months ago • 2 comments

Just want to double check this code is doing what's expected.

https://github.com/gpuweb/cts/blob/ade41b29ef2be93d160a141d53069e43969ff3cf/src/webgpu/gpu_test.ts#L164

    // Ensure devicePool.release is called for both providers even if one rejects.
    await Promise.all([
      this.provider?.then(x => devicePool.release(x)),
      this.mismatchedProvider?.then(x => mismatchedDevicePool.release(x)),
    ]);

It will call devicePool.release on both. It will not wait before proceeding as Promise.all continues as soon as one promise rejects.

Is that fine that it doesn't wait? If we want it to wait then I think you'd need something like

    // Ensure devicePool.release is called for both providers even if one rejects.
    const results = await Promise.allSettled([
      this.provider?.then(x => devicePool.release(x)),
      this.mismatchedProvider?.then(x => mismatchedDevicePool.release(x)),
    ]);

    const rejected = results.find(result => result.status === 'rejected');
    if (rejected) {
      throw rejected.reason;
    }

greggman avatar Apr 10 '25 00:04 greggman

@kainino0x

greggman avatar Apr 10 '25 00:04 greggman

Just to be clear, this doesn't fix the dawn.node issue. I was just in this area of the code, saw that comment, wasn't sure the code was doing what I interpreted the comment to mean, and started playing around. Even with this change, dawn.node still gets the same errors.

greggman avatar Apr 10 '25 04:04 greggman

// Ensure devicePool.release is called for both providers even if one rejects.

I think what this comment was saying is, make sure we call release on both of them. I.e. don't do:

await devicePool.release(x);
await mismatchedDevicePool.release(y);

However looking at what release() does, it would definitely be better to wait for both to settle (e.g. wait for x.lost even if something went wrong with y).

Your suggested code looks good to me.

kainino0x avatar Apr 15 '25 02:04 kainino0x