Skip to content
This repository was archived by the owner on Jul 6, 2018. It is now read-only.

Commit f43597b

Browse files
committed
http2: add configured debug statements
Using `./configure --debug-http2` will enable verbose debug statements from node.js, Using `./configure --debug-nghttp2` will enable verbose debug statements from nghttp2. The two can be used together PR-URL: #138 Reviewed-By: Matteo Collina <[email protected]>
1 parent 18785c8 commit f43597b

File tree

6 files changed

+167
-23
lines changed

6 files changed

+167
-23
lines changed

configure

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,15 @@ intl_optgroup.add_option('--download-path',
394394

395395
parser.add_option_group(intl_optgroup)
396396

397+
http2_optgroup.add_option('--debug-http2',
398+
action='store_true',
399+
dest='debug_http2',
400+
help='build with http2 debug statements on (default is false)')
401+
397402
http2_optgroup.add_option('--debug-nghttp2',
398403
action='store_true',
399404
dest='debug_nghttp2',
400-
help='Build nghttp2 with DEBUGBUILD')
405+
help='build nghttp2 with DEBUGBUILD (default is false)')
401406

402407
parser.add_option('--with-perfctr',
403408
action='store_true',
@@ -898,6 +903,11 @@ def configure_node(o):
898903
if options.enable_static:
899904
o['variables']['node_target_type'] = 'static_library'
900905

906+
if options.debug_http2:
907+
o['variables']['debug_http2'] = 1
908+
else:
909+
o['variables']['debug_http2'] = 'false'
910+
901911
if options.debug_nghttp2:
902912
o['variables']['debug_nghttp2'] = 1
903913
else:

node.gypi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
'NODE_RELEASE_URLBASE="<(node_release_urlbase)"',
5353
]
5454
}],
55+
[
56+
'debug_http2==1', {
57+
'defines': [ 'NODE_DEBUG_HTTP2=1' ]
58+
}],
5559
[ 'v8_enable_i18n_support==1', {
5660
'defines': [ 'NODE_HAVE_I18N_SUPPORT=1' ],
5761
'dependencies': [

src/node_http2.cc

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ void Http2Session::OnFreeSession() {
111111

112112
ssize_t Http2Session::OnMaxFrameSizePadding(size_t frameLen,
113113
size_t maxPayloadLen) {
114+
DEBUG_HTTP2("Http2Session: using max frame size padding\n");
114115
return maxPayloadLen;
115116
}
116117

117118
ssize_t Http2Session::OnCallbackPadding(size_t frameLen,
118119
size_t maxPayloadLen) {
120+
DEBUG_HTTP2("Http2Session: using callback padding\n");
119121
Isolate* isolate = env()->isolate();
120122
Local<Context> context = env()->context();
121123

@@ -146,7 +148,9 @@ void Http2Session::SetNextStreamID(const FunctionCallbackInfo<Value>& args) {
146148
Http2Session* session;
147149
ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder());
148150
nghttp2_session* s = session->session();
149-
nghttp2_session_set_next_stream_id(s, args[0]->Int32Value());
151+
int32_t id = args[0]->Int32Value();
152+
DEBUG_HTTP2("Http2Session: setting next stream id to %d\n", id);
153+
nghttp2_session_set_next_stream_id(s, id);
150154
}
151155

152156
void HttpErrorString(const FunctionCallbackInfo<Value>& args) {
@@ -193,6 +197,7 @@ void PackSettings(const FunctionCallbackInfo<Value>& args) {
193197

194198
// Used to fill in the spec defined initial values for each setting.
195199
void RefreshDefaultSettings(const FunctionCallbackInfo<Value>& args) {
200+
DEBUG_HTTP2("Http2Session: refreshing default settings\n");
196201
Environment* env = Environment::GetCurrent(args);
197202
int32_t* const buffer = env->http2_default_settings_buffer();
198203
buffer[IDX_SETTINGS_HEADER_TABLE_SIZE] =
@@ -207,6 +212,7 @@ void RefreshDefaultSettings(const FunctionCallbackInfo<Value>& args) {
207212

208213
template <get_setting fn>
209214
void RefreshSettings(const FunctionCallbackInfo<Value>& args) {
215+
DEBUG_HTTP2("Http2Session: refreshing settings for session\n");
210216
CHECK_EQ(args.Length(), 1);
211217
CHECK(args[0]->IsObject());
212218
Http2Session* session;
@@ -231,6 +237,7 @@ void RefreshSettings(const FunctionCallbackInfo<Value>& args) {
231237

232238
// Used to fill in the spec defined initial values for each setting.
233239
void RefreshSessionState(const FunctionCallbackInfo<Value>& args) {
240+
DEBUG_HTTP2("Http2Session: refreshing session state\n");
234241
CHECK_EQ(args.Length(), 1);
235242
CHECK(args[0]->IsObject());
236243
Environment* env = Environment::GetCurrent(args);
@@ -263,9 +270,10 @@ void RefreshStreamState(const FunctionCallbackInfo<Value>& args) {
263270
CHECK_EQ(args.Length(), 2);
264271
CHECK(args[0]->IsObject());
265272
CHECK(args[1]->IsNumber());
273+
int32_t id = args[1]->Int32Value();
274+
DEBUG_HTTP2("Http2Session: refreshing stream %d state\n", id);
266275
Http2Session* session;
267276
ASSIGN_OR_RETURN_UNWRAP(&session, args[0].As<Object>());
268-
int32_t id = args[1]->Int32Value();
269277
nghttp2_session* s = session->session();
270278
Nghttp2Stream* stream;
271279

@@ -313,7 +321,7 @@ void Http2Session::New(const FunctionCallbackInfo<Value>& args) {
313321

314322
nghttp2_session_type type =
315323
static_cast<nghttp2_session_type>(args[0]->IntegerValue());
316-
324+
DEBUG_HTTP2("Http2Session: creating a session of type: %d\n", type);
317325
new Http2Session(env, args.This(), type, args[1]);
318326
}
319327

@@ -327,6 +335,7 @@ void Http2Session::Consume(const FunctionCallbackInfo<Value>& args) {
327335
}
328336

329337
void Http2Session::Destroy(const FunctionCallbackInfo<Value>& args) {
338+
DEBUG_HTTP2("Http2Session: destroying session\n");
330339
Http2Session* session;
331340
ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder());
332341
session->Unconsume();
@@ -343,6 +352,9 @@ void Http2Session::SubmitPriority(const FunctionCallbackInfo<Value>& args) {
343352
int32_t weight = args[2]->Int32Value();
344353
bool exclusive = args[3]->BooleanValue();
345354
bool silent = args[4]->BooleanValue();
355+
DEBUG_HTTP2("Http2Session: submitting priority for stream %d: "
356+
"parent: %d, weight: %d, exclusive: %d, silent: %d\n",
357+
id, parent, weight, exclusive, silent);
346358
CHECK_GT(id, 0);
347359
CHECK_GE(parent, 0);
348360
CHECK_GE(weight, 0);
@@ -394,13 +406,17 @@ void Http2Session::SubmitRstStream(const FunctionCallbackInfo<Value>& args) {
394406
Http2Session* session;
395407
ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder());
396408

409+
int32_t id = args[0]->Int32Value();
410+
uint32_t code = args[1]->Uint32Value();
411+
397412
Nghttp2Stream* stream;
398-
if (!(stream = session->FindStream(args[0]->Int32Value()))) {
413+
if (!(stream = session->FindStream(id))) {
399414
// invalid stream
400415
return args.GetReturnValue().Set(NGHTTP2_ERR_INVALID_STREAM_ID);
401416
}
402-
args.GetReturnValue().Set(
403-
stream->SubmitRstStream(args[1]->Uint32Value()));
417+
DEBUG_HTTP2("Http2Session: sending rst_stream for stream %d, code: %d\n",
418+
id, code);
419+
args.GetReturnValue().Set(stream->SubmitRstStream(code));
404420
}
405421

406422
void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) {
@@ -418,19 +434,24 @@ void Http2Session::SubmitRequest(const FunctionCallbackInfo<Value>& args) {
418434

419435
Local<Array> headers = args[0].As<Array>();
420436
bool endStream = args[1]->BooleanValue();
421-
int32_t parent_id = args[2]->Int32Value();
437+
int32_t parent = args[2]->Int32Value();
422438
int32_t weight = args[3]->Int32Value();
423439
bool exclusive = args[4]->BooleanValue();
424440

441+
DEBUG_HTTP2("Http2Session: submitting request: headers: %d, end-stream: %d, "
442+
"parent: %d, weight: %d, exclusive: %d", headers->Length(),
443+
endStream, parent, weight, exclusive);
444+
425445
nghttp2_priority_spec prispec;
426-
nghttp2_priority_spec_init(&prispec, parent_id, weight, exclusive ? 1 : 0);
446+
nghttp2_priority_spec_init(&prispec, parent, weight, exclusive ? 1 : 0);
427447

428448
Headers list(isolate, headers);
429449

430-
args.GetReturnValue().Set(
431-
session->Nghttp2Session::SubmitRequest(&prispec,
432-
*list, list.length(),
433-
nullptr, endStream));
450+
int32_t ret = session->Nghttp2Session::SubmitRequest(&prispec,
451+
*list, list.length(),
452+
nullptr, endStream);
453+
DEBUG_HTTP2("Http2Session: request submitted, response: %d\n", ret);
454+
args.GetReturnValue().Set(ret);
434455
}
435456

436457
void Http2Session::SubmitResponse(const FunctionCallbackInfo<Value>& args) {
@@ -444,10 +465,14 @@ void Http2Session::SubmitResponse(const FunctionCallbackInfo<Value>& args) {
444465
Environment* env = session->env();
445466
Isolate* isolate = env->isolate();
446467

468+
int32_t id = args[0]->Int32Value();
447469
Local<Array> headers = args[1].As<Array>();
448470
bool endStream = args[2]->BooleanValue();
449471

450-
if (!(stream = session->FindStream(args[0]->Int32Value()))) {
472+
DEBUG_HTTP2("Http2Session: submitting response for stream %d: headers: %d, "
473+
"end-stream: %d\n", id, headers->Length(), endStream);
474+
475+
if (!(stream = session->FindStream(id))) {
451476
return args.GetReturnValue().Set(NGHTTP2_ERR_INVALID_STREAM_ID);
452477
}
453478

@@ -468,11 +493,16 @@ void Http2Session::SendHeaders(const FunctionCallbackInfo<Value>& args) {
468493
Environment* env = session->env();
469494
Isolate* isolate = env->isolate();
470495

471-
if (!(stream = session->FindStream(args[0]->Int32Value()))) {
496+
int32_t id = args[0]->Int32Value();
497+
Local<Array> headers = args[1].As<Array>();
498+
499+
DEBUG_HTTP2("Http2Session: sending informational headers for stream %d, "
500+
"count: %d\n", id, headers->Length());
501+
502+
if (!(stream = session->FindStream(id))) {
472503
return args.GetReturnValue().Set(NGHTTP2_ERR_INVALID_STREAM_ID);
473504
}
474505

475-
Local<Array> headers = args[1].As<Array>();
476506
Headers list(isolate, headers);
477507

478508
args.GetReturnValue().Set(stream->SubmitInfo(*list, list.length()));
@@ -483,7 +513,9 @@ void Http2Session::ShutdownStream(const FunctionCallbackInfo<Value>& args) {
483513
Http2Session* session;
484514
ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder());
485515
Nghttp2Stream* stream;
486-
if (!(stream = session->FindStream(args[0]->Int32Value()))) {
516+
int32_t id = args[0]->Int32Value();
517+
DEBUG_HTTP2("Http2Session: shutting down stream %d\n", id);
518+
if (!(stream = session->FindStream(id))) {
487519
return args.GetReturnValue().Set(NGHTTP2_ERR_INVALID_STREAM_ID);
488520
}
489521
stream->Shutdown();
@@ -517,10 +549,16 @@ void Http2Session::StreamReadStop(const FunctionCallbackInfo<Value>& args) {
517549
static void DoSessionShutdown(SessionShutdownWrap* req) {
518550
int status;
519551
if (req->graceful()) {
552+
DEBUG_HTTP2("Http2Session: initiating graceful session shutdown. "
553+
"last-stream-id: %d, code: %d\n",
554+
req->lastStreamID(), req->errorCode());
520555
status = nghttp2_session_terminate_session2(req->handle()->session(),
521556
req->lastStreamID(),
522557
req->errorCode());
523558
} else {
559+
DEBUG_HTTP2("Http2Session: initiating immediate shutdown. "
560+
"last-stream-id: %d, code: %d, opaque-data: %d\n",
561+
req->lastStreamID(), req->errorCode(), req->opaqueDataLength());
524562
status = nghttp2_submit_goaway(req->handle()->session(),
525563
NGHTTP2_FLAG_NONE,
526564
req->lastStreamID(),
@@ -593,6 +631,7 @@ void Http2Session::DestroyStream(const FunctionCallbackInfo<Value>& args) {
593631
CHECK_EQ(args.Length(), 1);
594632
CHECK(args[0]->IsNumber());
595633
int32_t id = args[0]->Int32Value();
634+
DEBUG_HTTP2("Http2Session: destroy stream %d\n", id);
596635
Nghttp2Stream* stream;
597636
if (!(stream = session->FindStream(id))) {
598637
return args.GetReturnValue().Set(NGHTTP2_ERR_INVALID_STREAM_ID);
@@ -610,17 +649,23 @@ void Http2Session::SubmitPushPromise(const FunctionCallbackInfo<Value>& args) {
610649
CHECK(args[1]->IsArray()); // headers array
611650

612651
Nghttp2Stream* parent;
652+
int32_t id = args[0]->Int32Value();
653+
Local<Array> headers = args[1].As<Array>();
654+
bool endStream = args[2]->BooleanValue();
613655

614-
if (!(parent = session->FindStream(args[0]->Int32Value()))) {
656+
DEBUG_HTTP2("Http2Session: submitting push promise for stream %d: "
657+
"end-stream: %d, headers: %d\n", id, endStream,
658+
headers->Length());
659+
660+
if (!(parent = session->FindStream(id))) {
615661
return args.GetReturnValue().Set(NGHTTP2_ERR_INVALID_STREAM_ID);
616662
}
617663

618-
Local<Array> headers = args[1].As<Array>();
619-
bool endStream = args[2]->BooleanValue();
620664
Headers list(isolate, headers);
621665

622666
int32_t ret = parent->SubmitPushPromise(*list, list.length(),
623667
nullptr, endStream);
668+
DEBUG_HTTP2("Http2Session: push promise submitted, ret: %d\n", ret);
624669
args.GetReturnValue().Set(ret);
625670
}
626671

@@ -674,7 +719,6 @@ void Http2Session::Send(uv_buf_t* buf, size_t length) {
674719
if (stream_ == nullptr || !stream_->IsAlive() || stream_->IsClosing()) {
675720
return;
676721
}
677-
678722
HandleScope scope(env()->isolate());
679723
SessionSendBuffer* req = ContainerOf(&SessionSendBuffer::buffer_, buf);
680724
uv_buf_t actual = uv_buf_init(buf->base, length);
@@ -685,6 +729,8 @@ void Http2Session::Send(uv_buf_t* buf, size_t length) {
685729

686730
void Http2Session::OnTrailers(Nghttp2Stream* stream,
687731
MaybeStackBuffer<nghttp2_nv>* trailers) {
732+
DEBUG_HTTP2("Http2Session: prompting for trailers on stream %d\n",
733+
stream->id());
688734
Local<Context> context = env()->context();
689735
Context::Scope context_scope(context);
690736
Isolate* isolate = env()->isolate();
@@ -1020,6 +1066,7 @@ void Http2Session::OnStreamReadImpl(ssize_t nread,
10201066

10211067

10221068
void Http2Session::Consume(Local<External> external) {
1069+
DEBUG_HTTP2("Http2Session: consuming socket\n");
10231070
CHECK(prev_alloc_cb_.is_empty());
10241071
StreamBase* stream = static_cast<StreamBase*>(external->Value());
10251072
CHECK_NE(stream, nullptr);
@@ -1033,6 +1080,7 @@ void Http2Session::Consume(Local<External> external) {
10331080

10341081

10351082
void Http2Session::Unconsume() {
1083+
DEBUG_HTTP2("Http2Session: unconsuming socket\n");
10361084
if (prev_alloc_cb_.is_empty())
10371085
return;
10381086
stream_->set_alloc_cb(prev_alloc_cb_);

0 commit comments

Comments
 (0)