Skip to content
Snippets Groups Projects
Commit a264964d authored by Vladimír Čunát's avatar Vladimír Čunát
Browse files

Merge !1164: daemon/http: improve handling of stream errors

parents c8cb9740 dca78626
Branches
Tags
1 merge request!1164daemon/http: improve handling of stream errors
Pipeline #79730 passed with stage
in 6 minutes and 27 seconds
......@@ -243,6 +243,15 @@ static void refuse_stream(nghttp2_session *h2, int32_t stream_id)
h2, NGHTTP2_FLAG_NONE, stream_id, NGHTTP2_REFUSED_STREAM);
}
/* Return the http ctx into a pristine state in which no stream is being processed. */
static void http_cleanup_stream(struct http_ctx *ctx)
{
ctx->incomplete_stream = -1;
ctx->current_method = HTTP_METHOD_NONE;
free(ctx->uri_path);
ctx->uri_path = NULL;
}
/*
* Save stream id from first header's frame.
*
......@@ -266,6 +275,7 @@ static int begin_headers_callback(nghttp2_session *h2, const nghttp2_frame *fram
"[http] stream %d incomplete, refusing\n", ctx->incomplete_stream);
refuse_stream(h2, stream_id);
} else {
http_cleanup_stream(ctx); // Free any leftover data and ensure pristine state
ctx->incomplete_stream = stream_id;
}
return 0;
......@@ -388,10 +398,7 @@ static int on_frame_recv_callback(nghttp2_session *h2, const nghttp2_frame *fram
refuse_stream(h2, stream_id);
}
}
ctx->incomplete_stream = -1;
ctx->current_method = HTTP_METHOD_NONE;
free(ctx->uri_path);
ctx->uri_path = NULL;
http_cleanup_stream(ctx);
len = ctx->buf_pos - sizeof(uint16_t);
if (len <= 0 || len > KNOT_WIRE_MAX_PKTSIZE) {
......@@ -431,6 +438,12 @@ static int on_stream_close_callback(nghttp2_session *h2, int32_t stream_id,
uint32_t error_code, void *user_data)
{
struct http_data *data;
struct http_ctx *ctx = (struct http_ctx *)user_data;
/* Ensure connection state is cleaned up in case the stream gets
* unexpectedly closed, e.g. by PROTOCOL_ERROR issued from nghttp2. */
if (ctx->incomplete_stream == stream_id)
http_cleanup_stream(ctx);
data = nghttp2_session_get_stream_user_data(h2, stream_id);
if (data)
......@@ -663,6 +676,7 @@ void http_free(struct http_ctx *ctx)
if (!ctx)
return;
http_cleanup_stream(ctx);
queue_deinit(ctx->streams);
nghttp2_session_del(ctx->h2);
free(ctx);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment