Fix assertion failure in nghttp2_stream.c

This is regression introduced in
46b70c1db8.
This commit is contained in:
Tatsuhiro Tsujikawa 2015-06-23 23:03:54 +09:00
parent 4870edb33d
commit 1945d0f02a
4 changed files with 48 additions and 1 deletions

View File

@ -356,7 +356,12 @@ static int stream_update_dep_on_detach_item(nghttp2_stream *stream,
return 0;
}
assert(stream->dpri == NGHTTP2_STREAM_DPRI_TOP);
if (stream->dpri == NGHTTP2_STREAM_DPRI_NO_ITEM) {
/* nghttp2_stream_defer_item() does not clear stream->item, but
set dpri = NGHTTP2_STREAM_DPRI_NO_ITEM. Catch this case
here. */
return 0;
}
stream->dpri = NGHTTP2_STREAM_DPRI_NO_ITEM;

View File

@ -266,6 +266,8 @@ int main(int argc _U_, char *argv[] _U_) {
test_nghttp2_session_send_data_callback) ||
!CU_add_test(pSuite, "session_on_begin_headers_temporal_failure",
test_nghttp2_session_on_begin_headers_temporal_failure) ||
!CU_add_test(pSuite, "session_defer_then_close",
test_nghttp2_session_defer_then_close) ||
!CU_add_test(pSuite, "http_mandatory_headers",
test_nghttp2_http_mandatory_headers) ||
!CU_add_test(pSuite, "http_content_length",

View File

@ -7469,6 +7469,45 @@ void test_nghttp2_session_on_begin_headers_temporal_failure(void) {
nghttp2_bufs_free(&bufs);
}
void test_nghttp2_session_defer_then_close(void) {
nghttp2_session *session;
nghttp2_session_callbacks callbacks;
nghttp2_data_provider prd;
int rv;
const uint8_t *datap;
ssize_t datalen;
nghttp2_frame frame;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.send_callback = null_send_callback;
nghttp2_session_client_new(&session, &callbacks, NULL);
prd.read_callback = defer_data_source_read_callback;
rv = nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), &prd, NULL);
CU_ASSERT(rv > 0);
/* This sends HEADERS */
datalen = nghttp2_session_mem_send(session, &datap);
CU_ASSERT(datalen > 0);
/* This makes DATA item deferred */
datalen = nghttp2_session_mem_send(session, &datap);
CU_ASSERT(datalen == 0);
nghttp2_frame_rst_stream_init(&frame.rst_stream, 1, NGHTTP2_CANCEL);
/* Assertion failure; GH-264 */
rv = nghttp2_session_on_rst_stream_received(session, &frame);
CU_ASSERT(rv == 0);
nghttp2_session_del(session);
}
static void check_nghttp2_http_recv_headers_fail(
nghttp2_session *session, nghttp2_hd_deflater *deflater, int32_t stream_id,
int stream_state, const nghttp2_nv *nva, size_t nvlen) {

View File

@ -126,6 +126,7 @@ void test_nghttp2_session_cancel_reserved_remote(void);
void test_nghttp2_session_reset_pending_headers(void);
void test_nghttp2_session_send_data_callback(void);
void test_nghttp2_session_on_begin_headers_temporal_failure(void);
void test_nghttp2_session_defer_then_close(void);
void test_nghttp2_http_mandatory_headers(void);
void test_nghttp2_http_content_length(void);
void test_nghttp2_http_content_length_mismatch(void);