[前][次][番号順一覧][スレッド一覧]

ruby-changes:59766

From: Xia <ko1@a...>
Date: Tue, 21 Jan 2020 22:42:07 +0900 (JST)
Subject: [ruby-changes:59766] 25f2005a63 (master): fix load error with EAGAIN

https://git.ruby-lang.org/ruby.git/commit/?id=25f2005a63

From 25f2005a638570cce832d218a451072057610f06 Mon Sep 17 00:00:00 2001
From: Xia Xionjun <xxjapp@g...>
Date: Tue, 21 Jan 2020 22:41:45 +0900
Subject: fix load error with EAGAIN

This is a fix related to the following issue.
rails/rails#33464

Not only in rails apps, some little ruby app with only 2 or 3 ruby
files reproduce the problem during many years.

When I edit linux ruby files by vs code via samba on windows, and
then I execute the ruby files on linux, "require_relative" will
sometimes not work properly.

My solution is to wait a monument if the required relative file is
busy.

diff --git a/io.c b/io.c
old mode 100644
new mode 100755
index 294abfe..51d92a9
--- a/io.c
+++ b/io.c
@@ -312,13 +312,31 @@ rb_cloexec_open(const char *pathname, int flags, mode_t mode) https://github.com/ruby/ruby/blob/trunk/io.c#L312
     int ret;
     static int o_cloexec_state = -1; /* <0: unknown, 0: ignored, >0: working */
 
+    static const int retry_interval = 0;
+    static const int retry_max_count = 10000;
+
+    int retry_count = 0;
+    int e;
+
 #ifdef O_CLOEXEC
     /* O_CLOEXEC is available since Linux 2.6.23.  Linux 2.6.18 silently ignore it. */
     flags |= O_CLOEXEC;
 #elif defined O_NOINHERIT
     flags |= O_NOINHERIT;
 #endif
-    ret = open(pathname, flags, mode);
+
+    while (1) {
+        ret = open(pathname, flags, mode);
+        e = errno;
+
+        if (ret != -1 || e != EAGAIN || retry_count >= retry_max_count) {
+            break;
+        }
+
+        retry_count++;
+        sleep(retry_interval);
+    }
+
     if (ret < 0) return ret;
     if (ret <= 2 || o_cloexec_state == 0) {
 	rb_maygvl_fd_fix_cloexec(ret);
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]