diff options
author | Xia Xionjun <xxjapp@gmail.com> | 2020-01-21 22:41:45 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-01-21 22:41:45 +0900 |
commit | 25f2005a638570cce832d218a451072057610f06 (patch) | |
tree | b48ee2d51143318bc05a1640120880ab00fc2b5b /io.c | |
parent | b0ca1fc21bbb9dac65a3b3f7b5935e691ece1501 (diff) |
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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2702
Diffstat (limited to 'io.c')
-rwxr-xr-x[-rw-r--r--] | io.c | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -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); |