From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

Waldek Kozaczuk discovered that nginx, using sendfile(), is experiencing
various failures when multiple concurrent connections are attempted.

It turns out that sendfile() had the wrong return type: Should have been
ssize_t (long), was int. So when sendfile() returned a -1, the application
sometimes thought it was a positive 4294967295. Of particular interest to
the nginx case, sendfile() is expected to temporarily fail when a non-
blocking socket's buffer is full, and this is "error" path is part of the
normal nginx operation, and did not happen correctly.

The fix is of course to change sendfile()'s return type to ssize_t, to match
Linux. Also in this patch we #include sys/sendfile.h to have the compiler
check the function's signature (if we had this #include earlier, we would
have caught this bug immediately).

Signed-off-by: Nadav Har'El <n...@scylladb.com>

---
diff --git a/fs/vfs/main.cc b/fs/vfs/main.cc
--- a/fs/vfs/main.cc
+++ b/fs/vfs/main.cc
@@ -38,6 +38,7 @@
 #include <sys/statvfs.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <sys/sendfile.h>

 #include <limits.h>
 #include <unistd.h>
@@ -2007,8 +2008,7 @@ int lchown(const char *path, uid_t owner, gid_t group)
 }


-extern "C"
-int sendfile(int out_fd, int in_fd, off_t *_offset, size_t count)
+ssize_t sendfile(int out_fd, int in_fd, off_t *_offset, size_t count)
 {
     struct file *in_fp;
     struct file *out_fp;
@@ -2086,6 +2086,7 @@ int sendfile(int out_fd, int in_fd, off_t *_offset, size_t count)
     return ret;
 }

+#undef sendfile64
 LFS64(sendfile);

NO_SYS(int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags));

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to