From a52ca391a2ccaf2436828274d12ede4697e9c8a9 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 10 Aug 2013 15:13:53 +0900 Subject: [PATCH] Do not RST_STREAM for DATA against nonexistent stream This may be useful to the misbehaving implementation, but it could result in lots of RST_STREAM, so just ignore it for now. --- lib/nghttp2_session.c | 9 +++++++-- tests/nghttp2_session_test.c | 12 ++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index e7dfd19e..10383f4a 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -2605,10 +2605,15 @@ int nghttp2_session_on_data_received(nghttp2_session *session, in this state it MUST respond with a stream error (Section 5.4.2) of type STREAM_CLOSED. */ - error_code = NGHTTP2_STREAM_CLOSED; + if(stream->state != NGHTTP2_STREAM_CLOSING) { + error_code = NGHTTP2_STREAM_CLOSED; + } } } else { - error_code = NGHTTP2_PROTOCOL_ERROR; + /* This should be treated as stream error, but it results in lots + of RST_STREAM. So just ignore frame against nonexistent stream + for now. */ + /* error_code = NGHTTP2_PROTOCOL_ERROR; */ } if(error_code != 0) { r = nghttp2_session_add_rst_stream(session, stream_id, error_code); diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index c65d8caa..72a854de 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -514,9 +514,11 @@ void test_nghttp2_session_recv_data(void) CU_ASSERT(0 == ud.data_chunk_recv_cb_called); CU_ASSERT(0 == ud.data_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item)); + /* DATA against nonexistent stream is ignored for now */ + CU_ASSERT(NULL == item); + /* CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item)); */ - CU_ASSERT(0 == nghttp2_session_send(session)); + /* CU_ASSERT(0 == nghttp2_session_send(session)); */ /* Create stream 1 with CLOSING state. DATA is ignored. */ stream = nghttp2_session_open_stream(session, 1, @@ -1212,8 +1214,10 @@ void test_nghttp2_session_on_data_received(void) CU_ASSERT(0 == nghttp2_session_on_data_received(session, 4096, NGHTTP2_FLAG_NONE, 6)); top = nghttp2_session_get_ob_pq_top(session); - CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(top)); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == OB_CTRL(top)->rst_stream.error_code); + /* DATA against nonexistent stream is just ignored for now */ + CU_ASSERT(top == NULL); + /* CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(top)); */ + /* CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == OB_CTRL(top)->rst_stream.error_code); */ nghttp2_session_del(session); }