From ee26469cd909aac26fcf733fd5d5c09cfe032a82 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 24 Apr 2014 23:44:34 +0900 Subject: [PATCH] Handle circular dependency Handle the situation if a stream is told to depend on its descendant. This is what http://tools.ietf.org/html/draft-ietf-httpbis-http2-12#section-5.3.3 says. --- lib/nghttp2_session.c | 7 ++++--- tests/nghttp2_session_test.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index ea50843d..8e820a8b 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -492,14 +492,15 @@ int nghttp2_session_reprioritize_stream return 0; } - /* Ignore priority request if resultant tree has cycle */ if(nghttp2_stream_dep_subtree_find(stream, dep_stream)) { DEBUGF(fprintf(stderr, - "stream: future cycle detected, dep_stream(%p)=%d " + "stream: cycle detected, dep_stream(%p)=%d " "stream(%p)=%d\n", dep_stream, dep_stream->stream_id, stream, stream->stream_id)); - return 0; + + nghttp2_stream_dep_remove_subtree(dep_stream); + nghttp2_stream_dep_make_root(dep_stream, &session->ob_pq); } nghttp2_stream_dep_remove_subtree(stream); diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index c16ade27..e1e5fdb8 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -2586,13 +2586,14 @@ void test_nghttp2_session_reprioritize_stream(void) CU_ASSERT(99 == stream->weight); CU_ASSERT(dep_stream == stream->dep_prev); - /* Test circular dependency; must be ignored */ + /* Test circular dependency; stream 1 is first removed and becomes + root. Then stream 3 depends on it. */ nghttp2_priority_spec_init(&pri_spec, 1, 1, 0); nghttp2_session_reprioritize_stream(session, dep_stream, &pri_spec); - CU_ASSERT(16 == dep_stream->weight); - CU_ASSERT(NULL == dep_stream->dep_prev); + CU_ASSERT(1 == dep_stream->weight); + CU_ASSERT(stream == dep_stream->dep_prev); nghttp2_session_del(session); }