[nginx] SPDY: improved logging.

Valentin Bartenev vbart at nginx.com
Thu May 15 15:25:52 UTC 2014


details:   http://hg.nginx.org/nginx/rev/701d6e17e42c
branches:  
changeset: 5693:701d6e17e42c
user:      Valentin Bartenev <vbart at nginx.com>
date:      Wed Apr 30 20:34:20 2014 +0400
description:
SPDY: improved logging.

diffstat:

 src/http/ngx_http_spdy.c               |  210 +++++++++++++++++++++++---------
 src/http/ngx_http_spdy_filter_module.c |    3 +-
 2 files changed, 151 insertions(+), 62 deletions(-)

diffs (truncated from 656 to 300 lines):

diff -r ed5fb7d22d46 -r 701d6e17e42c src/http/ngx_http_spdy.c
--- a/src/http/ngx_http_spdy.c	Thu May 15 19:22:06 2014 +0400
+++ b/src/http/ngx_http_spdy.c	Wed Apr 30 20:34:20 2014 +0400
@@ -395,8 +395,7 @@ ngx_http_spdy_init(ngx_event_t *rev)
     c = rev->data;
     hc = c->data;
 
-    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
-                   "init spdy request");
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "init spdy request");
 
     c->log->action = "processing SPDY";
 
@@ -556,7 +555,7 @@ ngx_http_spdy_read_handler(ngx_event_t *
 
         if (n == 0 && (sc->incomplete || sc->processing)) {
             ngx_log_error(NGX_LOG_INFO, c->log, 0,
-                          "client closed prematurely connection");
+                          "client prematurely closed connection");
         }
 
         if (n == 0 || n == NGX_ERROR) {
@@ -644,7 +643,7 @@ ngx_http_spdy_write_handler(ngx_event_t 
         stream->handled = 0;
 
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
-                       "spdy run stream %ui", stream->id);
+                       "run spdy stream %ui", stream->id);
 
         wev = stream->request->connection->write;
         wev->handler(wev);
@@ -860,7 +859,7 @@ ngx_http_spdy_state_head(ngx_http_spdy_c
     pos += sizeof(uint32_t);
 
     ngx_log_debug3(NGX_LOG_DEBUG_HTTP, sc->connection->log, 0,
-                   "spdy process frame head:%08XD f:%Xd l:%uz",
+                   "process spdy frame head:%08XD f:%Xd l:%uz",
                    head, sc->flags, sc->length);
 
     if (ngx_spdy_ctl_frame_check(head)) {
@@ -872,6 +871,8 @@ ngx_http_spdy_state_head(ngx_http_spdy_c
             return ngx_http_spdy_state_syn_stream(sc, pos, end);
 
         case NGX_SPDY_SYN_REPLY:
+            ngx_log_error(NGX_LOG_INFO, sc->connection->log, 0,
+                          "client sent unexpected SYN_REPLY frame");
             return ngx_http_spdy_state_protocol_error(sc);
 
         case NGX_SPDY_RST_STREAM:
@@ -887,6 +888,8 @@ ngx_http_spdy_state_head(ngx_http_spdy_c
             return ngx_http_spdy_state_skip(sc, pos, end); /* TODO */
 
         case NGX_SPDY_HEADERS:
+            ngx_log_error(NGX_LOG_INFO, sc->connection->log, 0,
+                          "client sent unexpected HEADERS frame");
             return ngx_http_spdy_state_protocol_error(sc);
 
         case NGX_SPDY_WINDOW_UPDATE:
@@ -904,10 +907,8 @@ ngx_http_spdy_state_head(ngx_http_spdy_c
         return ngx_http_spdy_state_data(sc, pos, end);
     }
 
-
-    /* TODO version & type check */
-    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, sc->connection->log, 0,
-                   "spdy unknown frame");
+    ngx_log_error(NGX_LOG_INFO, sc->connection->log, 0,
+                  "client sent invalid frame");
 
     return ngx_http_spdy_state_protocol_error(sc);
 }
@@ -927,7 +928,10 @@ ngx_http_spdy_state_syn_stream(ngx_http_
     }
 
     if (sc->length <= NGX_SPDY_SYN_STREAM_SIZE) {
-        /* TODO logging */
+        ngx_log_error(NGX_LOG_INFO, sc->connection->log, 0,
+                      "client sent SYN_STREAM frame with incorrect length %uz",
+                      sc->length);
+
         return ngx_http_spdy_state_protocol_error(sc);
     }
 
@@ -968,7 +972,7 @@ ngx_http_spdy_state_syn_stream(ngx_http_
     if (sc->processing >= sscf->concurrent_streams) {
 
         ngx_log_error(NGX_LOG_INFO, sc->connection->log, 0,
-                      "spdy concurrent streams exceeded %ui", sc->processing);
+                      "concurrent streams exceeded %ui", sc->processing);
 
         if (ngx_http_spdy_send_rst_stream(sc, sid, NGX_SPDY_REFUSED_STREAM,
                                           prio)
@@ -1026,7 +1030,7 @@ ngx_http_spdy_state_headers(ngx_http_spd
     r = sc->stream->request;
 
     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                   "spdy process HEADERS %uz of %uz", size, sc->length);
+                   "process spdy header block %uz of %uz", size, sc->length);
 
     buf = r->header_in;
 
@@ -1101,7 +1105,7 @@ ngx_http_spdy_state_headers(ngx_http_spd
         buf->pos += NGX_SPDY_NV_NUM_SIZE;
 
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                       "spdy HEADERS block consists of %ui entries",
+                       "spdy header block has %ui entries",
                        sc->entries);
 
         if (ngx_list_init(&r->headers_in.headers, r->pool, 20,
@@ -1142,7 +1146,6 @@ ngx_http_spdy_state_headers(ngx_http_spd
                 rc = ngx_http_spdy_alloc_large_header_buffer(r);
 
                 if (rc == NGX_DECLINED) {
-                    /* TODO logging */
                     ngx_http_finalize_request(r,
                                             NGX_HTTP_REQUEST_HEADER_TOO_LARGE);
                     return ngx_http_spdy_state_headers_skip(sc, pos, end);
@@ -1179,9 +1182,8 @@ ngx_http_spdy_state_headers(ngx_http_spd
             }
 
             if (complete) {
-                /* TODO: improve error message */
                 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                               "spdy again while last chunk");
+                               "premature end of spdy header block");
 
                 return ngx_http_spdy_state_headers_error(sc, pos, end);
             }
@@ -1190,13 +1192,7 @@ ngx_http_spdy_state_headers(ngx_http_spd
                                             ngx_http_spdy_state_headers);
 
         case NGX_HTTP_PARSE_INVALID_HEADER:
-
-            /* TODO: improve error message */
-            ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
-                          "client sent invalid header line");
-
             ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
-
             return ngx_http_spdy_state_headers_skip(sc, pos, end);
 
         default: /* NGX_ERROR */
@@ -1262,6 +1258,9 @@ ngx_http_spdy_state_headers_skip(ngx_htt
                                         ngx_http_spdy_state_headers_skip);
     }
 
+    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, sc->connection->log, 0,
+                   "spdy header block skip %uz of %uz", size, sc->length);
+
     sc->zstream_in.next_in = pos;
     sc->zstream_in.avail_in = (size < sc->length) ? size : sc->length;
 
@@ -1364,7 +1363,7 @@ ngx_http_spdy_state_window_update(ngx_ht
             ngx_log_error(NGX_LOG_INFO, sc->connection->log, 0,
                           "client violated flow control for stream %ui: "
                           "received WINDOW_UPDATE frame with delta %uz "
-                          "that is not allowed for window %z",
+                          "not allowed for window %z",
                           sid, delta, stream->send_window);
 
             if (ngx_http_spdy_terminate_stream(sc, stream,
@@ -1397,7 +1396,7 @@ ngx_http_spdy_state_window_update(ngx_ht
             ngx_log_error(NGX_LOG_INFO, sc->connection->log, 0,
                           "client violated connection flow control: "
                           "received WINDOW_UPDATE frame with delta %uz "
-                          "that is not allowed for window %uz",
+                          "not allowed for window %uz",
                           delta, sc->send_window);
 
             return ngx_http_spdy_state_protocol_error(sc);
@@ -1440,8 +1439,8 @@ ngx_http_spdy_state_data(ngx_http_spdy_c
 
     if (sc->length > sc->recv_window) {
         ngx_log_error(NGX_LOG_INFO, sc->connection->log, 0,
-                      "client violated connection flow control: length of "
-                      "received DATA frame %uz, while available window %uz",
+                      "client violated connection flow control: "
+                      "received DATA frame length %uz, available window %uz",
                       sc->length, sc->recv_window);
 
         return ngx_http_spdy_state_protocol_error(sc);
@@ -1465,13 +1464,16 @@ ngx_http_spdy_state_data(ngx_http_spdy_c
     stream = sc->stream;
 
     if (stream == NULL) {
+        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, sc->connection->log, 0,
+                       "unknown spdy stream");
+
         return ngx_http_spdy_state_skip(sc, pos, end);
     }
 
     if (sc->length > stream->recv_window) {
         ngx_log_error(NGX_LOG_INFO, sc->connection->log, 0,
-                      "client violated flow control for stream %ui: length of "
-                      "received DATA frame %uz, while available window %uz",
+                      "client violated flow control for stream %ui: "
+                      "received DATA frame length %uz, available window %uz",
                       stream->id, sc->length, stream->recv_window);
 
         if (ngx_http_spdy_terminate_stream(sc, stream,
@@ -1501,7 +1503,7 @@ ngx_http_spdy_state_data(ngx_http_spdy_c
 
     if (stream->in_closed) {
         ngx_log_error(NGX_LOG_INFO, sc->connection->log, 0,
-                      "client sent DATA frame for half closed stream %ui",
+                      "client sent DATA frame for half-closed stream %ui",
                       stream->id);
 
         if (ngx_http_spdy_terminate_stream(sc, stream,
@@ -1544,7 +1546,10 @@ ngx_http_spdy_state_read_data(ngx_http_s
             stream->in_closed = 1;
         }
 
-        /* TODO log and accounting */
+        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, sc->connection->log, 0,
+                       "skipping spdy DATA frame, reason: %d",
+                       stream->skip_data);
+
         return ngx_http_spdy_state_skip(sc, pos, end);
     }
 
@@ -1573,7 +1578,10 @@ ngx_http_spdy_state_read_data(ngx_http_s
         if (r->headers_in.content_length_n != -1
             && r->headers_in.content_length_n < rb->rest)
         {
-            /* TODO logging */
+            ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
+                          "client intended to send body data "
+                          "larger than declared");
+
             stream->skip_data = NGX_SPDY_DATA_ERROR;
             goto error;
 
@@ -1584,9 +1592,8 @@ ngx_http_spdy_state_read_data(ngx_http_s
                 && clcf->client_max_body_size < rb->rest)
             {
                 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
-                              "client intended to send too large chunked "
-                              "body: %O bytes",
-                              rb->rest);
+                              "client intended to send "
+                              "too large chunked body: %O bytes", rb->rest);
 
                 stream->skip_data = NGX_SPDY_DATA_ERROR;
                 goto error;
@@ -1638,7 +1645,7 @@ ngx_http_spdy_state_read_data(ngx_http_s
         } else if (r->headers_in.content_length_n != rb->rest) {
             ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
                           "client prematurely closed stream: "
-                          "%O of %O bytes of request body received",
+                          "only %O out of %O bytes of request body received",
                           rb->rest, r->headers_in.content_length_n);
 
             stream->skip_data = NGX_SPDY_DATA_ERROR;
@@ -1717,9 +1724,11 @@ ngx_http_spdy_state_rst_stream(ngx_http_
                    "spdy RST_STREAM sid:%ui st:%ui", sid, status);
 
     stream = ngx_http_spdy_get_stream_by_id(sc, sid);
+
     if (stream == NULL) {
         ngx_log_debug0(NGX_LOG_DEBUG_HTTP, sc->connection->log, 0,
-                       "unknown stream, probably it has been closed already");
+                       "unknown spdy stream");
+
         return ngx_http_spdy_state_complete(sc, pos, end);
     }
 
@@ -1738,7 +1747,7 @@ ngx_http_spdy_state_rst_stream(ngx_http_
 
     case NGX_SPDY_INTERNAL_ERROR:
         ngx_log_error(NGX_LOG_INFO, fc->log, 0,
-                      "client terminated stream %ui because of internal error",
+                      "client terminated stream %ui due to internal error",
                       sid);
         break;
 
@@ -1770,7 +1779,10 @@ ngx_http_spdy_state_ping(ngx_http_spdy_c
     }
 
     if (sc->length != NGX_SPDY_PING_SIZE) {
-        /* TODO logging */
+        ngx_log_error(NGX_LOG_INFO, sc->connection->log, 0,
+                      "client sent PING frame with incorrect length %uz",
+                      sc->length);
+
         return ngx_http_spdy_state_protocol_error(sc);
     }
 
@@ -1810,6 +1822,9 @@ ngx_http_spdy_state_skip(ngx_http_spdy_c
 
     size = end - pos;
 
+    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, sc->connection->log, 0,
+                   "spdy frame skip %uz of %uz", size, sc->length);
+
     if (size < sc->length) {
         sc->length -= size;
         return ngx_http_spdy_state_save(sc, end, end,
@@ -1839,13 +1854,16 @@ ngx_http_spdy_state_settings(ngx_http_sp



More information about the nginx-devel mailing list