You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by yl...@apache.org on 2022/04/21 10:02:29 UTC

svn commit: r1900100 - in /httpd/httpd/trunk: changes-entries/osx_nopush.txt server/core_filters.c

Author: ylavic
Date: Thu Apr 21 10:02:29 2022
New Revision: 1900100

URL: http://svn.apache.org/viewvc?rev=1900100&view=rev
Log:
core: Disable TCP_NOPUSH optimization on OSX. BZ 66019.

OSX supports TCP_NOPUSH but does not release the data retained (in TCP stack)
when the option is unset. It seems that unsetting it before the last write
does not help either so just disable the optimization for OSX in the core
output filter to avoid uncontrollable transmission delays.

* server/core_filters.c():
  Add the sock_nopush() helper that does nothing on OSX and platforms not
  supporting TCP_NOPUSH or TCP_CORK.

* server/core_filters.c(send_brigade_nonblocking):
  Use sock_nopush() instead of apr_socket_opt_set() for APR_TCP_NOPUSH option.


Added:
    httpd/httpd/trunk/changes-entries/osx_nopush.txt
Modified:
    httpd/httpd/trunk/server/core_filters.c

Added: httpd/httpd/trunk/changes-entries/osx_nopush.txt
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/changes-entries/osx_nopush.txt?rev=1900100&view=auto
==============================================================================
--- httpd/httpd/trunk/changes-entries/osx_nopush.txt (added)
+++ httpd/httpd/trunk/changes-entries/osx_nopush.txt Thu Apr 21 10:02:29 2022
@@ -0,0 +1,2 @@
+  *) core: Disable TCP_NOPUSH optimization on OSX since it might introduce
+     transmission delays.  PR 66019.  [Yann Ylavic]

Modified: httpd/httpd/trunk/server/core_filters.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/core_filters.c?rev=1900100&r1=1900099&r2=1900100&view=diff
==============================================================================
--- httpd/httpd/trunk/server/core_filters.c (original)
+++ httpd/httpd/trunk/server/core_filters.c Thu Apr 21 10:02:29 2022
@@ -493,6 +493,18 @@ static void delete_meta_bucket(apr_bucke
     apr_bucket_delete(bucket);
 }
 
+static APR_INLINE void sock_nopush(apr_socket_t *s, int to)
+{
+    /* Disable TCP_NOPUSH handling on OSX since unsetting it won't push
+     * retained data, which might introduce delays if further data don't
+     * come soon enough or cause the last chunk to be sent only when the
+     * connection is shutdown (e.g. after KeepAliveTimeout).
+     */
+#if APR_TCP_NOPUSH_FLAG && !defined(__APPLE__)
+    (void)apr_socket_opt_set(s, APR_TCP_NOPUSH, to);
+#endif
+}
+
 static apr_status_t send_brigade_nonblocking(apr_socket_t *s,
                                              apr_bucket_brigade *bb,
                                              core_output_ctx_t *ctx,
@@ -514,7 +526,7 @@ static apr_status_t send_brigade_nonbloc
 #if APR_HAS_SENDFILE
         if (can_sendfile_bucket(bucket)) {
             if (nvec > 0) {
-                (void)apr_socket_opt_set(s, APR_TCP_NOPUSH, 1);
+                sock_nopush(s, 1);
                 rv = writev_nonblocking(s, bb, ctx, nbytes, nvec, c);
                 if (rv != APR_SUCCESS) {
                     goto cleanup;
@@ -544,7 +556,7 @@ static apr_status_t send_brigade_nonbloc
                     nbytes = 0;
                     nvec = 0;
                 }
-                (void)apr_socket_opt_set(s, APR_TCP_NOPUSH, 0);
+                sock_nopush(s, 0);
 
                 rv = apr_bucket_read(bucket, &data, &length, APR_BLOCK_READ);
             }
@@ -572,7 +584,7 @@ static apr_status_t send_brigade_nonbloc
         /* Make sure that these new data fit in our iovec. */
         if (nvec == ctx->nvec) {
             if (nvec == NVEC_MAX) {
-                (void)apr_socket_opt_set(s, APR_TCP_NOPUSH, 1);
+                sock_nopush(s, 1);
                 rv = writev_nonblocking(s, bb, ctx, nbytes, nvec, c);
                 if (rv != APR_SUCCESS) {
                     goto cleanup;
@@ -610,7 +622,7 @@ static apr_status_t send_brigade_nonbloc
         if (nbytes > sconf->flush_max_threshold
                 && next != APR_BRIGADE_SENTINEL(bb)
                 && next->length && !is_in_memory_bucket(next)) {
-            (void)apr_socket_opt_set(s, APR_TCP_NOPUSH, 1);
+            sock_nopush(s, 1);
             rv = writev_nonblocking(s, bb, ctx, nbytes, nvec, c);
             if (rv != APR_SUCCESS) {
                 goto cleanup;
@@ -624,7 +636,7 @@ static apr_status_t send_brigade_nonbloc
     }
 
 cleanup:
-    (void)apr_socket_opt_set(s, APR_TCP_NOPUSH, 0);
+    sock_nopush(s, 0);
     return rv;
 }