Skip to content
Snippets Groups Projects
  1. Dec 05, 2019
  2. Nov 19, 2019
  3. Nov 18, 2019
  4. Nov 19, 2019
  5. Nov 18, 2019
  6. Nov 06, 2019
  7. Oct 21, 2019
  8. Oct 24, 2019
  9. Oct 22, 2019
  10. Oct 21, 2019
    • Maxim Dounin's avatar
      Win32: silenced -Wcast-function-type GCC warning (ticket #1865). · 2393e25a
      Maxim Dounin authored
      With MinGW-w64, building 64-bit nginx binary with GCC 8 and above
      results in warning due to cast of GetProcAddress() result to ngx_wsapoll_pt,
      which GCC thinks is incorrect.  Added intermediate cast to "void *" to
      silence the warning.
      2393e25a
    • Maxim Dounin's avatar
      Win32: improved fallback on FormatMessage() errors. · 9aa906a6
      Maxim Dounin authored
      FormatMessage() seems to return many errors which essentially indicate that
      the language in question is not available.  At least the following were
      observed in the wild and during testing: ERROR_MUI_FILE_NOT_FOUND (15100)
      (ticket #1868), ERROR_RESOURCE_TYPE_NOT_FOUND (1813).  While documentation
      says it should be ERROR_RESOURCE_LANG_NOT_FOUND (1815), this doesn't seem
      to be the case.
      
      As such, checking error code was removed, and as long as FormatMessage()
      returns an error, we now always try the default language.
      9aa906a6
  11. Oct 17, 2019
    • Maxim Dounin's avatar
      SSL: available bytes handling (ticket #1431). · 798fcf1a
      Maxim Dounin authored
      Added code to track number of bytes available in the socket.
      This makes it possible to avoid looping for a long time while
      working with fast enough peer when data are added to the socket buffer
      faster than we are able to read and process data.
      
      When kernel does not provide number of bytes available, it is
      retrieved using ioctl(FIONREAD) as long as a buffer is filled by
      SSL_read().
      
      It is assumed that number of bytes returned by SSL_read() is close
      to the number of bytes read from the socket, as we do not use
      SSL compression.  But even if it is not true for some reason, this
      is not important, as we post an additional reading event anyway.
      
      Note that data can be buffered at SSL layer, and it is not possible
      to simply stop reading at some point and wait till the event will
      be reported by the kernel again.  This can be only done when there
      are no data in SSL buffers, and there is no good way to find out if
      it's the case.
      
      Instead of trying to figure out if SSL buffers are empty, this patch
      introduces events posted for the next event loop iteration - such
      events will be processed only on the next event loop iteration,
      after going into the kernel and retrieving additional events.  This
      seems to be simple and reliable approach.
      798fcf1a
    • Maxim Dounin's avatar
      Events: available bytes calculation via ioctl(FIONREAD). · fac4c7bd
      Maxim Dounin authored
      This makes it possible to avoid looping for a long time while working
      with a fast enough peer when data are added to the socket buffer faster
      than we are able to read and process them (ticket #1431).  This is
      basically what we already do on FreeBSD with kqueue, where information
      about the number of bytes in the socket buffer is returned by
      the kevent() call.
      
      With other event methods rev->available is now set to -1 when the socket
      is ready for reading.  Later in ngx_recv() and ngx_recv_chain(), if
      full buffer is received, real number of bytes in the socket buffer is
      retrieved using ioctl(FIONREAD).  Reading more than this number of bytes
      ensures that even with edge-triggered event methods the event will be
      triggered again, so it is safe to stop processing of the socket and
      switch to other connections.
      
      Using ioctl(FIONREAD) only after reading a full buffer is an optimization.
      With this approach we only call ioctl(FIONREAD) when there are at least
      two recv()/readv() calls.
      fac4c7bd
    • Maxim Dounin's avatar
      SSL: improved ngx_ssl_recv_chain() to stop if c->read->ready is 0. · d2ea2262
      Maxim Dounin authored
      As long as there are data to read in the socket, yet the amount of data
      is less than total size of the buffers in the chain, this saves one
      unneeded read() syscall.  Before this change, reading only stopped if
      ngx_ssl_recv() returned no data, that is, two read() syscalls in a row
      returned EAGAIN.
      d2ea2262
    • Maxim Dounin's avatar
      Event pipe: disabled c->read->available checking for SSL. · 60609f23
      Maxim Dounin authored
      In SSL connections, data can be buffered by the SSL layer, and it is
      wrong to avoid doing c->recv_chain() if c->read->available is 0 and
      c->read->pending_eof is set.  And tests show that the optimization in
      question indeed can result in incorrect detection of premature connection
      close if upstream closes the connection without sending a close notify
      alert at the same time.  Fix is to disable c->read->available optimization
      for SSL connections.
      60609f23
  12. Oct 15, 2019
  13. Oct 08, 2019
  14. Sep 30, 2019
  15. Sep 24, 2019
  16. Sep 23, 2019
    • Ruslan Ermilov's avatar
      HTTP/2: fixed worker_shutdown_timeout. · 6052881a
      Ruslan Ermilov authored
      6052881a
    • Ruslan Ermilov's avatar
      HTTP/2: fixed possible alert about left open socket on shutdown. · f878492a
      Ruslan Ermilov authored
      This could happen when graceful shutdown configured by worker_shutdown_timeout
      times out and is then followed by another timeout such as proxy_read_timeout.
      In this case, the HEADERS frame is added to the output queue, but attempt to
      send it fails (due to c->error forcibly set during graceful shutdown timeout).
      This triggers request finalization which attempts to close the stream.  But the
      stream cannot be closed because there is a frame in the output queue, and the
      connection cannot be finalized.  This leaves the connection open without any
      timer events leading to alert.
      
      The fix is to post write event when sending output queue fails on c->error.
      That will finalize the connection.
      f878492a
  17. Sep 18, 2019
    • Maxim Dounin's avatar
      HTTP/2: traffic-based flood detection. · af0e284b
      Maxim Dounin authored
      With this patch, all traffic over an HTTP/2 connection is counted in
      the h2c->total_bytes field, and payload traffic is counted in
      the h2c->payload_bytes field.  As long as total traffic is many times
      larger than payload traffic, we consider this to be a flood.
      af0e284b
    • Maxim Dounin's avatar
      HTTP/2: switched back to RST_STREAM with NO_ERROR. · 4d4201fa
      Maxim Dounin authored
      In 8df664ebe037, we've switched to maximizing stream window instead
      of sending RST_STREAM.  Since then handling of RST_STREAM with NO_ERROR
      was fixed at least in Chrome, hence we switch back to using RST_STREAM.
      
      This allows more effective rejecting of large bodies, and also minimizes
      non-payload traffic to be accounted in the next patch.
      4d4201fa
  18. Sep 16, 2019
  19. Sep 10, 2019
    • Sergey Kandaurov's avatar
      Resolver: fixed possible use-after-free while resolving PTR. · 4cd1dd28
      Sergey Kandaurov authored
      Previously, if a response to the PTR request was cached, and ngx_resolver_dup()
      failed to allocate memory for the resulting name, then the original node was
      freed but left in expire_queue.  A subsequent address resolving would end up
      in a use-after-free memory access of the node either in ngx_resolver_expire()
      or ngx_resolver_process_ptr(), when accessing it through expire_queue.
      
      The fix is to leave the resolver node intact.
      4cd1dd28
    • Ruslan Ermilov's avatar
      HTTP/2: close connection on zero WINDOW_UPDATE. · c3f80987
      Ruslan Ermilov authored
      Don't waste server resources by sending RST_STREAM frames.  Instead,
      reject WINDOW_UPDATE frames with invalid zero increment by closing
      connection with PROTOCOL_ERROR.
      c3f80987
    • Ruslan Ermilov's avatar
      HTTP/2: close connection on frames with self-dependency. · 456e2139
      Ruslan Ermilov authored
      Don't waste server resources by sending RST_STREAM frames.  Instead,
      reject HEADERS and PRIORITY frames with self-dependency by closing
      connection with PROTOCOL_ERROR.
      456e2139
  20. Sep 04, 2019
    • Sergey Kandaurov's avatar
      Fixed "return" with discarding invalid chunked body. · 5a2ce3f4
      Sergey Kandaurov authored
      When ngx_http_discard_request_body() call was added to ngx_http_send_response(),
      there were no return codes other than NGX_OK and NGX_HTTP_INTERNAL_SERVER_ERROR.
      Now it can also return NGX_HTTP_BAD_REQUEST, but ngx_http_send_response() still
      incorrectly transforms it to NGX_HTTP_INTERNAL_SERVER_ERROR.
      
      The fix is to propagate ngx_http_discard_request_body() errors.
      5a2ce3f4
  21. Sep 03, 2019
    • Sergey Kandaurov's avatar
      Detect runaway chunks in ngx_http_parse_chunked(). · 77c01f10
      Sergey Kandaurov authored
      As defined in HTTP/1.1, body chunks have the following ABNF:
      
         chunk = chunk-size [ chunk-ext ] CRLF chunk-data CRLF
      
      where chunk-data is a sequence of chunk-size octets.
      
      With this change, chunk-data that doesn't end up with CRLF at chunk-size
      offset will be treated as invalid, such as in the example provided below:
      
      4
      SEE-THIS-AND-
      4
      THAT
      0
      77c01f10
  22. Aug 19, 2019
    • Sergey Kandaurov's avatar
      HTTP/2: discard remaining request body after redirect. · 9cb22efa
      Sergey Kandaurov authored
      Previously, if unbuffered request body reading wasn't finished before
      the request was redirected to a different location using error_page
      or X-Accel-Redirect, and the request body is read again, this could
      lead to disastrous effects, such as a duplicate post_handler call or
      "http request count is zero" alert followed by a segmentation fault.
      
      This happened in the following configuration (ticket #1819):
      
          location / {
              proxy_request_buffering off;
              proxy_pass http://bad;
              proxy_intercept_errors on;
              error_page 502 = /error;
          }
      
          location /error {
              proxy_pass http://backend;
          }
      9cb22efa