Răsfoiți Sursa

http2: fix http2 race condition issue.

Nick Peng 16 ore în urmă
părinte
comite
20aa651a13
3 a modificat fișierele cu 12 adăugiri și 1 ștergeri
  1. 2 0
      src/dns_client/client_http2.c
  2. 7 0
      src/dns_server/server_http2.c
  3. 3 1
      src/http_parse/http2.c

+ 2 - 0
src/dns_client/client_http2.c

@@ -510,6 +510,7 @@ static int _dns_client_http2_process_read(struct dns_server_info *server_info)
 
 			conn_stream = (struct dns_conn_stream *)http2_stream_get_ex_data(stream);
 			if (conn_stream == NULL) {
+				http2_stream_put(stream);
 				continue;
 			}
 
@@ -530,6 +531,7 @@ static int _dns_client_http2_process_read(struct dns_server_info *server_info)
 					}
 				}
 			}
+			http2_stream_put(stream);
 		}
 
 		if (poll_count < 128) {

+ 7 - 0
src/dns_server/server_http2.c

@@ -244,6 +244,9 @@ int _dns_server_process_http2(struct dns_server_conn_tls_client *tls_client, str
 			if (ret < 0) {
 				break;
 			}
+			if (poll_count > 0 && poll_items[0].stream) {
+				http2_stream_put(poll_items[0].stream);
+			}
 		}
 	}
 
@@ -305,6 +308,10 @@ int _dns_server_process_http2(struct dns_server_conn_tls_client *tls_client, str
 				if (poll_items[i].stream && poll_items[i].readable) {
 					_dns_server_http2_process_stream(tls_client, poll_items[i].stream);
 				}
+				
+				if (poll_items[i].stream) {
+					http2_stream_put(poll_items[i].stream); /* Release poll reference */
+				}
 			}
 		}
 	}

+ 3 - 1
src/http_parse/http2.c

@@ -1530,7 +1530,7 @@ static void _http2_ctx_collect_ready_streams(struct http2_ctx *ctx, struct http2
 
 		if (readable || (check_writable && writable)) {
 			if (*count < max_items) {
-				items[*count].stream = stream;
+				items[*count].stream = http2_stream_get(stream);
 				items[*count].readable = readable;
 				items[*count].writable = writable;
 				(*count)++;
@@ -1632,6 +1632,7 @@ void http2_stream_close(struct http2_stream *stream)
 		return;
 	}
 
+	http2_stream_get(stream); /* Ensure stream survives during close */
 	struct http2_ctx *ctx = stream->ctx;
 	if (ctx) {
 		pthread_mutex_lock(&ctx->mutex);
@@ -1645,6 +1646,7 @@ void http2_stream_close(struct http2_stream *stream)
 	stream->state = HTTP2_STREAM_CLOSED;
 
 	http2_stream_put(stream);
+	http2_stream_put(stream);
 }
 
 int http2_stream_get_id(struct http2_stream *stream)