You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
6.3 KiB

  1. From 912e8f18ef274fdda0a522b2aa8255bddd00fb7b Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Wed, 30 Aug 2017 07:35:35 +0200
  4. Subject: [PATCH] BUG/MEDIUM: connection: remove useless flag CO_FL_DATA_RD_SH
  5. This flag is both confusing and wrong. It is supposed to report the
  6. fact that the data layer has received a shutdown, but in fact this is
  7. reported by CO_FL_SOCK_RD_SH which is set by the transport layer after
  8. this condition is detected. The only case where the flag above is set
  9. is in the stream interface where CF_SHUTR is also set on the receiving
  10. channel.
  11. In addition, it was checked in the health checks code (while never set)
  12. and was always test jointly with CO_FL_SOCK_RD_SH everywhere, except in
  13. conn_data_read0_pending() which incorrectly doesn't match the second
  14. time it's called and is fortunately protected by an extra check on
  15. (ic->flags & CF_SHUTR).
  16. This patch gets rid of the flag completely. Now conn_data_read0_pending()
  17. accurately reports the fact that the transport layer has detected the end
  18. of the stream, regardless of the fact that this state was already consumed,
  19. and the stream interface watches ic->flags&CF_SHUTR to know if the channel
  20. was already closed by the upper layer (which it already used to do).
  21. The now unused conn_data_read0() function was removed.
  22. (cherry picked from commit 54e917cfa1e7b0539550ae32c48c76da2f169041)
  23. [wt: this happens to fix a real bug which occasionally strikes when
  24. using http-reuse in the rare case where a server shuts down after
  25. providing its response but before the connection is put back into
  26. the idle pool, and it gets immediately recycled for another request,
  27. without first passing through the idle handler, and the already
  28. reported shutdown is never reported to the second transaction,
  29. causing a loop to last for as long as the server timeout]
  30. ---
  31. contrib/debug/flags.c | 1 -
  32. include/proto/connection.h | 8 +-------
  33. include/types/connection.h | 2 +-
  34. src/checks.c | 4 ++--
  35. src/stream_interface.c | 11 +++++------
  36. 5 files changed, 9 insertions(+), 17 deletions(-)
  37. diff --git a/contrib/debug/flags.c b/contrib/debug/flags.c
  38. index bc71bde9..19327f34 100644
  39. --- a/contrib/debug/flags.c
  40. +++ b/contrib/debug/flags.c
  41. @@ -117,7 +117,6 @@ void show_conn_flags(unsigned int f)
  42. SHOW_FLAG(f, CO_FL_SOCK_WR_SH);
  43. SHOW_FLAG(f, CO_FL_SOCK_RD_SH);
  44. SHOW_FLAG(f, CO_FL_DATA_WR_SH);
  45. - SHOW_FLAG(f, CO_FL_DATA_RD_SH);
  46. SHOW_FLAG(f, CO_FL_WAKE_DATA);
  47. SHOW_FLAG(f, CO_FL_INIT_DATA);
  48. SHOW_FLAG(f, CO_FL_ADDR_TO_SET);
  49. diff --git a/include/proto/connection.h b/include/proto/connection.h
  50. index fce60259..eb68322a 100644
  51. --- a/include/proto/connection.h
  52. +++ b/include/proto/connection.h
  53. @@ -413,12 +413,6 @@ static inline void conn_sock_read0(struct connection *c)
  54. fdtab[c->t.sock.fd].linger_risk = 0;
  55. }
  56. -static inline void conn_data_read0(struct connection *c)
  57. -{
  58. - c->flags |= CO_FL_DATA_RD_SH;
  59. - __conn_data_stop_recv(c);
  60. -}
  61. -
  62. static inline void conn_sock_shutw(struct connection *c)
  63. {
  64. c->flags |= CO_FL_SOCK_WR_SH;
  65. @@ -450,7 +444,7 @@ static inline void conn_data_shutw_hard(struct connection *c)
  66. /* detect sock->data read0 transition */
  67. static inline int conn_data_read0_pending(struct connection *c)
  68. {
  69. - return (c->flags & (CO_FL_DATA_RD_SH | CO_FL_SOCK_RD_SH)) == CO_FL_SOCK_RD_SH;
  70. + return (c->flags & CO_FL_SOCK_RD_SH) != 0;
  71. }
  72. /* detect data->sock shutw transition */
  73. diff --git a/include/types/connection.h b/include/types/connection.h
  74. index 02eac932..90e8e073 100644
  75. --- a/include/types/connection.h
  76. +++ b/include/types/connection.h
  77. @@ -90,7 +90,7 @@ enum {
  78. CO_FL_WAKE_DATA = 0x00008000, /* wake-up data layer upon activity at the transport layer */
  79. /* flags used to remember what shutdown have been performed/reported */
  80. - CO_FL_DATA_RD_SH = 0x00010000, /* DATA layer was notified about shutr/read0 */
  81. + /* unused : 0x00010000 */
  82. CO_FL_DATA_WR_SH = 0x00020000, /* DATA layer asked for shutw */
  83. CO_FL_SOCK_RD_SH = 0x00040000, /* SOCK layer was notified about shutr/read0 */
  84. CO_FL_SOCK_WR_SH = 0x00080000, /* SOCK layer asked for shutw */
  85. diff --git a/src/checks.c b/src/checks.c
  86. index ca3881a5..6c5e3cbc 100644
  87. --- a/src/checks.c
  88. +++ b/src/checks.c
  89. @@ -839,7 +839,7 @@ static void event_srv_chk_r(struct connection *conn)
  90. done = 0;
  91. conn->xprt->rcv_buf(conn, check->bi, check->bi->size);
  92. - if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_DATA_RD_SH)) {
  93. + if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH)) {
  94. done = 1;
  95. if ((conn->flags & CO_FL_ERROR) && !check->bi->i) {
  96. /* Report network errors only if we got no other data. Otherwise
  97. @@ -2892,7 +2892,7 @@ static void tcpcheck_main(struct connection *conn)
  98. goto out_end_tcpcheck;
  99. if (conn->xprt->rcv_buf(conn, check->bi, check->bi->size) <= 0) {
  100. - if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_DATA_RD_SH)) {
  101. + if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH)) {
  102. done = 1;
  103. if ((conn->flags & CO_FL_ERROR) && !check->bi->i) {
  104. /* Report network errors only if we got no other data. Otherwise
  105. diff --git a/src/stream_interface.c b/src/stream_interface.c
  106. index 836487bd..aba49c94 100644
  107. --- a/src/stream_interface.c
  108. +++ b/src/stream_interface.c
  109. @@ -1060,14 +1060,14 @@ static void si_conn_recv_cb(struct connection *conn)
  110. if (conn->flags & CO_FL_ERROR)
  111. return;
  112. - /* stop here if we reached the end of data */
  113. - if (conn_data_read0_pending(conn))
  114. - goto out_shutdown_r;
  115. -
  116. /* maybe we were called immediately after an asynchronous shutr */
  117. if (ic->flags & CF_SHUTR)
  118. return;
  119. + /* stop here if we reached the end of data */
  120. + if (conn_data_read0_pending(conn))
  121. + goto out_shutdown_r;
  122. +
  123. cur_read = 0;
  124. if ((ic->flags & (CF_STREAMER | CF_STREAMER_FAST)) && !ic->buf->o &&
  125. @@ -1153,7 +1153,7 @@ static void si_conn_recv_cb(struct connection *conn)
  126. * that if such an event is not handled above in splice, it will be handled here by
  127. * recv().
  128. */
  129. - while (!(conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_DATA_RD_SH | CO_FL_WAIT_ROOM | CO_FL_HANDSHAKE))) {
  130. + while (!(conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_WAIT_ROOM | CO_FL_HANDSHAKE)) && !(ic->flags & CF_SHUTR)) {
  131. max = channel_recv_max(ic);
  132. if (!max) {
  133. @@ -1267,7 +1267,6 @@ static void si_conn_recv_cb(struct connection *conn)
  134. if (ic->flags & CF_AUTO_CLOSE)
  135. channel_shutw_now(ic);
  136. stream_sock_read0(si);
  137. - conn_data_read0(conn);
  138. return;
  139. }
  140. --
  141. 2.13.5