Attempt to fix TSAN

pull/13391/head
ncteisen 7 years ago
parent 692915ee07
commit abbdbf9374
  1. 16
      test/core/end2end/fixtures/http_proxy_fixture.cc

@ -88,9 +88,11 @@ typedef struct proxy_connection {
grpc_slice_buffer client_read_buffer; grpc_slice_buffer client_read_buffer;
grpc_slice_buffer client_deferred_write_buffer; grpc_slice_buffer client_deferred_write_buffer;
bool client_is_writing;
grpc_slice_buffer client_write_buffer; grpc_slice_buffer client_write_buffer;
grpc_slice_buffer server_read_buffer; grpc_slice_buffer server_read_buffer;
grpc_slice_buffer server_deferred_write_buffer; grpc_slice_buffer server_deferred_write_buffer;
bool server_is_writing;
grpc_slice_buffer server_write_buffer; grpc_slice_buffer server_write_buffer;
grpc_http_parser http_parser; grpc_http_parser http_parser;
@ -148,6 +150,7 @@ static void proxy_connection_failed(grpc_exec_ctx* exec_ctx,
static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg, static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg,
grpc_error* error) { grpc_error* error) {
proxy_connection* conn = (proxy_connection*)arg; proxy_connection* conn = (proxy_connection*)arg;
conn->client_is_writing = false;
if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE) {
proxy_connection_failed(exec_ctx, conn, true /* is_client */, proxy_connection_failed(exec_ctx, conn, true /* is_client */,
"HTTP proxy client write", error); "HTTP proxy client write", error);
@ -160,6 +163,7 @@ static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg,
if (conn->client_deferred_write_buffer.length > 0) { if (conn->client_deferred_write_buffer.length > 0) {
grpc_slice_buffer_move_into(&conn->client_deferred_write_buffer, grpc_slice_buffer_move_into(&conn->client_deferred_write_buffer,
&conn->client_write_buffer); &conn->client_write_buffer);
conn->client_is_writing = true;
grpc_endpoint_write(exec_ctx, conn->client_endpoint, grpc_endpoint_write(exec_ctx, conn->client_endpoint,
&conn->client_write_buffer, &conn->client_write_buffer,
&conn->on_client_write_done); &conn->on_client_write_done);
@ -173,6 +177,7 @@ static void on_client_write_done(grpc_exec_ctx* exec_ctx, void* arg,
static void on_server_write_done(grpc_exec_ctx* exec_ctx, void* arg, static void on_server_write_done(grpc_exec_ctx* exec_ctx, void* arg,
grpc_error* error) { grpc_error* error) {
proxy_connection* conn = (proxy_connection*)arg; proxy_connection* conn = (proxy_connection*)arg;
conn->server_is_writing = false;
if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE) {
proxy_connection_failed(exec_ctx, conn, false /* is_client */, proxy_connection_failed(exec_ctx, conn, false /* is_client */,
"HTTP proxy server write", error); "HTTP proxy server write", error);
@ -185,6 +190,7 @@ static void on_server_write_done(grpc_exec_ctx* exec_ctx, void* arg,
if (conn->server_deferred_write_buffer.length > 0) { if (conn->server_deferred_write_buffer.length > 0) {
grpc_slice_buffer_move_into(&conn->server_deferred_write_buffer, grpc_slice_buffer_move_into(&conn->server_deferred_write_buffer,
&conn->server_write_buffer); &conn->server_write_buffer);
conn->server_is_writing = true;
grpc_endpoint_write(exec_ctx, conn->server_endpoint, grpc_endpoint_write(exec_ctx, conn->server_endpoint,
&conn->server_write_buffer, &conn->server_write_buffer,
&conn->on_server_write_done); &conn->on_server_write_done);
@ -210,13 +216,14 @@ static void on_client_read_done(grpc_exec_ctx* exec_ctx, void* arg,
// the current write is finished. // the current write is finished.
// //
// Otherwise, move the read data into the write buffer and write it. // Otherwise, move the read data into the write buffer and write it.
if (conn->server_write_buffer.length > 0) { if (conn->server_is_writing) {
grpc_slice_buffer_move_into(&conn->client_read_buffer, grpc_slice_buffer_move_into(&conn->client_read_buffer,
&conn->server_deferred_write_buffer); &conn->server_deferred_write_buffer);
} else { } else {
grpc_slice_buffer_move_into(&conn->client_read_buffer, grpc_slice_buffer_move_into(&conn->client_read_buffer,
&conn->server_write_buffer); &conn->server_write_buffer);
proxy_connection_ref(conn, "client_read"); proxy_connection_ref(conn, "client_read");
conn->server_is_writing = true;
grpc_endpoint_write(exec_ctx, conn->server_endpoint, grpc_endpoint_write(exec_ctx, conn->server_endpoint,
&conn->server_write_buffer, &conn->server_write_buffer,
&conn->on_server_write_done); &conn->on_server_write_done);
@ -242,13 +249,14 @@ static void on_server_read_done(grpc_exec_ctx* exec_ctx, void* arg,
// the current write is finished. // the current write is finished.
// //
// Otherwise, move the read data into the write buffer and write it. // Otherwise, move the read data into the write buffer and write it.
if (conn->client_write_buffer.length > 0) { if (conn->client_is_writing) {
grpc_slice_buffer_move_into(&conn->server_read_buffer, grpc_slice_buffer_move_into(&conn->server_read_buffer,
&conn->client_deferred_write_buffer); &conn->client_deferred_write_buffer);
} else { } else {
grpc_slice_buffer_move_into(&conn->server_read_buffer, grpc_slice_buffer_move_into(&conn->server_read_buffer,
&conn->client_write_buffer); &conn->client_write_buffer);
proxy_connection_ref(conn, "server_read"); proxy_connection_ref(conn, "server_read");
conn->client_is_writing = true;
grpc_endpoint_write(exec_ctx, conn->client_endpoint, grpc_endpoint_write(exec_ctx, conn->client_endpoint,
&conn->client_write_buffer, &conn->client_write_buffer,
&conn->on_client_write_done); &conn->on_client_write_done);
@ -262,6 +270,7 @@ static void on_server_read_done(grpc_exec_ctx* exec_ctx, void* arg,
static void on_write_response_done(grpc_exec_ctx* exec_ctx, void* arg, static void on_write_response_done(grpc_exec_ctx* exec_ctx, void* arg,
grpc_error* error) { grpc_error* error) {
proxy_connection* conn = (proxy_connection*)arg; proxy_connection* conn = (proxy_connection*)arg;
conn->client_is_writing = false;
if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE) {
proxy_connection_failed(exec_ctx, conn, true /* is_client */, proxy_connection_failed(exec_ctx, conn, true /* is_client */,
"HTTP proxy write response", error); "HTTP proxy write response", error);
@ -302,6 +311,7 @@ static void on_server_connect_done(grpc_exec_ctx* exec_ctx, void* arg,
grpc_slice slice = grpc_slice slice =
grpc_slice_from_copied_string("HTTP/1.0 200 connected\r\n\r\n"); grpc_slice_from_copied_string("HTTP/1.0 200 connected\r\n\r\n");
grpc_slice_buffer_add(&conn->client_write_buffer, slice); grpc_slice_buffer_add(&conn->client_write_buffer, slice);
conn->client_is_writing = true;
grpc_endpoint_write(exec_ctx, conn->client_endpoint, grpc_endpoint_write(exec_ctx, conn->client_endpoint,
&conn->client_write_buffer, &conn->client_write_buffer,
&conn->on_write_response_done); &conn->on_write_response_done);
@ -450,9 +460,11 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg,
grpc_combiner_scheduler(conn->proxy->combiner)); grpc_combiner_scheduler(conn->proxy->combiner));
grpc_slice_buffer_init(&conn->client_read_buffer); grpc_slice_buffer_init(&conn->client_read_buffer);
grpc_slice_buffer_init(&conn->client_deferred_write_buffer); grpc_slice_buffer_init(&conn->client_deferred_write_buffer);
conn->client_is_writing = false;
grpc_slice_buffer_init(&conn->client_write_buffer); grpc_slice_buffer_init(&conn->client_write_buffer);
grpc_slice_buffer_init(&conn->server_read_buffer); grpc_slice_buffer_init(&conn->server_read_buffer);
grpc_slice_buffer_init(&conn->server_deferred_write_buffer); grpc_slice_buffer_init(&conn->server_deferred_write_buffer);
conn->server_is_writing = false;
grpc_slice_buffer_init(&conn->server_write_buffer); grpc_slice_buffer_init(&conn->server_write_buffer);
grpc_http_parser_init(&conn->http_parser, GRPC_HTTP_REQUEST, grpc_http_parser_init(&conn->http_parser, GRPC_HTTP_REQUEST,
&conn->http_request); &conn->http_request);

Loading…
Cancel
Save