From 25f2005a638570cce832d218a451072057610f06 Mon Sep 17 00:00:00 2001 From: Xia Xionjun 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. --- io.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) mode change 100644 => 100755 io.c (limited to 'io.c') diff --git a/io.c b/io.c old mode 100644 new mode 100755 index 294abfe6b0..51d92a942f --- a/io.c +++ b/io.c @@ -312,13 +312,31 @@ rb_cloexec_open(const char *pathname, int flags, mode_t mode) 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 v1.2.3