Ticket #5650: 0001-Avoid-busy-looping-on-WANTREAD-within-connection_han.patch

File 0001-Avoid-busy-looping-on-WANTREAD-within-connection_han.patch, 2.0 KB (added by nickm, 6 years ago)

possible fix for #5650

  • src/or/connection.c

    From 098b085a89187efc7ffb1a68d7fed14521d4063f Mon Sep 17 00:00:00 2001
    From: Nick Mathewson <nickm@torproject.org>
    Date: Wed, 10 Apr 2013 19:30:41 -0400
    Subject: [PATCH] Avoid busy-looping on WANTREAD within connection_handle_write
    
    possible fix for 5650.
    ---
     src/or/connection.c | 7 +++++++
     src/or/or.h         | 3 +++
     2 files changed, 10 insertions(+)
    
    diff --git a/src/or/connection.c b/src/or/connection.c
    index eac9c4f..327466e 100644
    a b connection_read_to_buf(connection_t *conn, ssize_t *max_to_read, 
    28262826        connection_start_writing(conn);
    28272827        return 0;
    28282828      case TOR_TLS_WANTREAD: /* we're already reading */
     2829        if (conn->in_connection_handle_write)
     2830          connection_stop_writing(conn);
     2831        result = 0;
     2832        break;
    28292833      case TOR_TLS_DONE: /* no data read, so nothing to process */
    28302834        result = 0;
    28312835        break; /* so we call bucket_decrement below */
    connection_handle_write_impl(connection_t *conn, int force) 
    32313235      }
    32323236      return 0;
    32333237    } else if (conn->state == OR_CONN_STATE_TLS_SERVER_RENEGOTIATING) {
     3238
    32343239      return connection_handle_read(conn);
    32353240    }
    32363241
    connection_handle_write(connection_t *conn, int force) 
    33373342{
    33383343    int res;
    33393344    tor_gettimeofday_cache_clear();
     3345    conn->in_connection_handle_write = 1;
    33403346    res = connection_handle_write_impl(conn, force);
     3347    conn->in_connection_handle_write = 0;
    33413348    return res;
    33423349}
    33433350
  • src/or/or.h

    diff --git a/src/or/or.h b/src/or/or.h
    index 51c23d3..6728b86 100644
    a b typedef struct connection_t { 
    998998  /** Set to 1 when we're inside connection_flushed_some to keep us from
    999999   * calling connection_handle_write() recursively. */
    10001000  unsigned int in_flushed_some:1;
     1001  /** True if connection_handle_write is currently running on this connection.
     1002   */
     1003  unsigned int in_connection_handle_write:1;
    10011004
    10021005  /* For linked connections:
    10031006   */