| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 893e918 commit 478f1e7
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -587,7 +587,7 @@ AsyncWrap::AsyncWrap(Environment* env, | |||
| 587 | 587 | provider_type_ = provider; | |
| 588 | 588 | ||
| 589 | 589 | // Use AsyncReset() call to execute the init() callbacks. | |
| 590 | - AsyncReset(execution_async_id, silent); | ||
| 590 | + AsyncReset(object, execution_async_id, silent); | ||
| 591 | 591 | init_hook_ran_ = true; | |
| 592 | 592 | } | |
| 593 | 593 | ||
@@ -653,10 +653,6 @@ void AsyncWrap::EmitDestroy(Environment* env, double async_id) { | |||
| 653 | 653 | env->destroy_async_id_list()->push_back(async_id); | |
| 654 | 654 | } | |
| 655 | 655 | ||
| 656 | - void AsyncWrap::AsyncReset(double execution_async_id, bool silent) { | ||
| 657 | - AsyncReset(object(), execution_async_id, silent); | ||
| 658 | - } | ||
| 659 | - | ||
| 660 | 656 | // Generalized call for both the constructor and for handles that are pooled | |
| 661 | 657 | // and reused over their lifetime. This way a new uid can be assigned when | |
| 662 | 658 | // the resource is pulled out of the pool and put back into use. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -170,9 +170,6 @@ class AsyncWrap : public BaseObject { | |||
| 170 | 170 | double execution_async_id = kInvalidAsyncId, | |
| 171 | 171 | bool silent = false); | |
| 172 | 172 | ||
| 173 | - void AsyncReset(double execution_async_id = kInvalidAsyncId, | ||
| 174 | - bool silent = false); | ||
| 175 | - | ||
| 176 | 173 | // Only call these within a valid HandleScope. | |
| 177 | 174 | v8::MaybeLocal<v8::Value> MakeCallback(const v8::Local<v8::Function> cb, | |
| 178 | 175 | int argc, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -369,7 +369,12 @@ int FileHandle::ReadStart() { | |||
| 369 | 369 | if (freelist.size() > 0) { | |
| 370 | 370 | read_wrap = std::move(freelist.back()); | |
| 371 | 371 | freelist.pop_back(); | |
| 372 | - read_wrap->AsyncReset(); | ||
| 372 | + // Use a fresh async resource. | ||
| 373 | + // Lifetime is ensured via AsyncWrap::resource_. | ||
| 374 | + Local<Object> resource = Object::New(env()->isolate()); | ||
| 375 | + resource->Set( | ||
| 376 | + env()->context(), env()->handle_string(), read_wrap->object()); | ||
| 377 | + read_wrap->AsyncReset(resource); | ||
| 373 | 378 | read_wrap->file_handle_ = this; | |
| 374 | 379 | } else { | |
| 375 | 380 | Local<Object> wrap_obj; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,65 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const initHooks = require('./init-hooks'); | ||
| 5 | + const { checkInvocations } = require('./hook-checks'); | ||
| 6 | + const fixtures = require('../common/fixtures'); | ||
| 7 | + if (!common.hasCrypto) | ||
| 8 | + common.skip('missing crypto'); | ||
| 9 | + const http2 = require('http2'); | ||
| 10 | + const assert = require('assert'); | ||
| 11 | + const fs = require('fs'); | ||
| 12 | + | ||
| 13 | + // Checks that the async resource is not reused by FileHandle. | ||
| 14 | + // Test is based on parallel\test-http2-respond-file-fd.js. | ||
| 15 | + | ||
| 16 | + const hooks = initHooks(); | ||
| 17 | + hooks.enable(); | ||
| 18 | + | ||
| 19 | + const { | ||
| 20 | + HTTP2_HEADER_CONTENT_TYPE | ||
| 21 | + } = http2.constants; | ||
| 22 | + | ||
| 23 | + // Use large fixture to get several file operations. | ||
| 24 | + const fname = fixtures.path('person-large.jpg'); | ||
| 25 | + const fd = fs.openSync(fname, 'r'); | ||
| 26 | + | ||
| 27 | + const server = http2.createServer(); | ||
| 28 | + server.on('stream', (stream) => { | ||
| 29 | + stream.respondWithFD(fd, { | ||
| 30 | + [HTTP2_HEADER_CONTENT_TYPE]: 'text/plain' | ||
| 31 | + }); | ||
| 32 | + }); | ||
| 33 | + server.on('close', common.mustCall(() => fs.closeSync(fd))); | ||
| 34 | + server.listen(0, () => { | ||
| 35 | + const client = http2.connect(`http://localhost:${server.address().port}`); | ||
| 36 | + const req = client.request(); | ||
| 37 | + | ||
| 38 | + req.on('response', common.mustCall()); | ||
| 39 | + req.on('data', () => {}); | ||
| 40 | + req.on('end', common.mustCall(() => { | ||
| 41 | + client.close(); | ||
| 42 | + server.close(); | ||
| 43 | + })); | ||
| 44 | + req.end(); | ||
| 45 | + }); | ||
| 46 | + | ||
| 47 | + process.on('exit', onExit); | ||
| 48 | + | ||
| 49 | + function onExit() { | ||
| 50 | + hooks.disable(); | ||
| 51 | + hooks.sanityCheck(); | ||
| 52 | + const activities = hooks.activities; | ||
| 53 | + | ||
| 54 | + // Verify both invocations | ||
| 55 | + const fsReqs = activities.filter((x) => x.type === 'FSREQCALLBACK'); | ||
| 56 | + assert.ok(fsReqs.length >= 2); | ||
| 57 | + | ||
| 58 | + checkInvocations(fsReqs[0], { init: 1, destroy: 1 }, 'when process exits'); | ||
| 59 | + checkInvocations(fsReqs[1], { init: 1, destroy: 1 }, 'when process exits'); | ||
| 60 | + | ||
| 61 | + // Verify reuse handle has been wrapped | ||
| 62 | + assert.ok(fsReqs[0].handle !== fsReqs[1].handle, 'Resource reused'); | ||
| 63 | + assert.ok(fsReqs[0].handle === fsReqs[1].handle.handle, | ||
| 64 | + 'Resource not wrapped correctly'); | ||
| 65 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments