1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.
This commit is contained in:
Xia Xionjun 2020-01-21 22:41:45 +09:00 committed by Nobuyoshi Nakada
parent b0ca1fc21b
commit 25f2005a63
Notes: git 2020-01-21 22:42:13 +09:00

20
io.c Normal file → Executable file
View file

@ -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);