GeezerVison is showing github.com — http2: keep session objects alive during Http2Scope · nodejs/node@55f6bdb
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_http2.cc +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -71,6 +71,11 @@ Http2Scope::Http2Scope(Http2Session* session) { |
71 | 71 | } |
72 | 72 | session->flags_ |= SESSION_STATE_HAS_SCOPE; |
73 | 73 | session_ = session; |
| 74 | + |
| 75 | + // Always keep the session object alive for at least as long as |
| 76 | + // this scope is active. |
| 77 | + session_handle_ = session->object(); |
| 78 | + CHECK(!session_handle_.IsEmpty()); |
74 | 79 | } |
75 | 80 |
|
76 | 81 | Http2Scope::~Http2Scope() { |
@@ -512,6 +517,7 @@ void Http2Session::Unconsume() { |
512 | 517 | } |
513 | 518 |
|
514 | 519 | Http2Session::~Http2Session() { |
| 520 | + CHECK_EQ(flags_ & SESSION_STATE_HAS_SCOPE, 0); |
515 | 521 | if (!object().IsEmpty()) |
516 | 522 | ClearWrap(object()); |
517 | 523 | persistent().Reset(); |
@@ -1365,6 +1371,7 @@ void Http2Session::OnStreamReadImpl(ssize_t nread, |
1365 | 1371 | void* ctx) { |
1366 | 1372 | Http2Session* session = static_cast<Http2Session*>(ctx); |
1367 | 1373 | Http2Scope h2scope(session); |
| 1374 | + CHECK_NE(session->stream_, nullptr); |
1368 | 1375 | DEBUG_HTTP2SESSION2(session, "receiving %d bytes", nread); |
1369 | 1376 | if (nread < 0) { |
1370 | 1377 | uv_buf_t tmp_buf; |
|
Collapse file
Copy file name to clipboardExpand all lines: src/node_http2.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -444,6 +444,7 @@ class Http2Scope { |
444 | 444 |
|
445 | 445 | private: |
446 | 446 | Http2Session* session_ = nullptr; |
| 447 | + Local<Object> session_handle_; |
447 | 448 | }; |
448 | 449 |
|
449 | 450 | // The Http2Options class is used to parse the options object passed in to |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-http2-createwritereq.js +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | 'use strict'; |
2 | 2 |
|
| 3 | +// Flags: --expose-gc |
| 4 | + |
3 | 5 | const common = require('../common'); |
4 | 6 | if (!common.hasCrypto) |
5 | 7 | common.skip('missing crypto'); |
@@ -62,6 +64,15 @@ server.listen(0, common.mustCall(function() { |
62 | 64 | } |
63 | 65 | })); |
64 | 66 |
|
| 67 | + // Ref: https://github.com/nodejs/node/issues/17840 |
| 68 | + const origDestroy = req.destroy; |
| 69 | + req.destroy = function(...args) { |
| 70 | + // Schedule a garbage collection event at the end of the current |
| 71 | + // MakeCallback() run. |
| 72 | + process.nextTick(global.gc); |
| 73 | + return origDestroy.call(this, ...args); |
| 74 | + }; |
| 75 | + |
65 | 76 | req.end(); |
66 | 77 | }); |
67 | 78 | })); |