[ruby-cvs:73271] normal:r66171 (trunk): process.c: fix ETXTBUSY from MJIT compiler process

normal at ruby-lang.org normal at ruby-lang.org
Tue Dec 4 04:49:54 JST 2018


normal	2018-12-04 04:49:54 +0900 (Tue, 04 Dec 2018)

  New Revision: 66171

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66171

  Log:
    process.c: fix ETXTBUSY from MJIT compiler process
    
    This affects test/ruby/test_process.rb (test_execopt_env_path).
    
    Since MJIT uses vfork+execve in a separate thread, there can be
    small window in-between vfork and execve where tmp_script.cmd is
    held open by the vforked child.  vfork only pauses the MJIT
    thread, not any Ruby Threads, so our call to Process.spawn will
    hit ETXTBUSY in that window unless we fork.
    
    main thread                       | MJIT thread
    ----------------------------------------------------
    fd = open(tmp)                    |                |
                                      | vfork for CC   |   CC running
    write                             |                | ---------------
    fchmod                            |                |  sees "fd" here
    close(fd)                         |                |
        Process.spawn called          |                |
    vfork  (spawn)|    (new process)  |                |
                  | execve => TXTBUSY |                |
                  |                   |                | execve (FD_CLOEXEC on fd)
                  |                   | vfork returns  |
    
    Holding the waitpid_lock whenever we intend to spawn a process
    prevents the MJIT thread from spawning a process while we are
    spawning in Ruby-land.

  Modified files:
    trunk/process.c
    trunk/test/ruby/test_process.rb


More information about the ruby-cvs mailing list