|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// Aborting a queued stat must cancel the libuv request instead of running it. |
| 4 | +// The threadpool is saturated so the request is still queued when it is |
| 5 | +// cancelled; the queue is FIFO, so the stat cannot start before the blocker. |
| 6 | + |
| 7 | +const common = require('../common'); |
| 8 | + |
| 9 | +if (!common.hasCrypto) common.skip('missing crypto'); |
| 10 | + |
| 11 | +const assert = require('assert'); |
| 12 | +const crypto = require('crypto'); |
| 13 | +const { spawnSyncAndExitWithoutError } = require('../common/child_process'); |
| 14 | + |
| 15 | +if (process.argv[2] !== 'child') { |
| 16 | + spawnSyncAndExitWithoutError( |
| 17 | + process.execPath, |
| 18 | + ['--expose-internals', __filename, 'child'], |
| 19 | + { env: { ...process.env, UV_THREADPOOL_SIZE: '1' } }, |
| 20 | + ); |
| 21 | + return; |
| 22 | +} |
| 23 | + |
| 24 | +// A single worker is what keeps the stat queued behind the blocker below. |
| 25 | +assert.strictEqual(process.env.UV_THREADPOOL_SIZE, '1'); |
| 26 | + |
| 27 | +const { internalBinding } = require('internal/test/binding'); |
| 28 | +const binding = internalBinding('fs'); |
| 29 | + |
| 30 | +// Occupy the only worker thread so the stat below cannot start. |
| 31 | +crypto.pbkdf2('secret', 'salt', 500_000, 32, 'sha512', common.mustCall()); |
| 32 | + |
| 33 | +const req = new binding.FSReqCallback(false); |
| 34 | +req.oncomplete = common.mustCall((err) => { |
| 35 | + // Without cancellation the stat would run and report success. |
| 36 | + assert.strictEqual(err?.code, 'ECANCELED'); |
| 37 | +}); |
| 38 | +binding.stat(__filename, false, req, true); |
| 39 | +req.cancel(); |
0 commit comments