ruby-changes:50658
From: usa <ko1@a...>
Date: Mon, 19 Mar 2018 00:07:29 +0900 (JST)
Subject: [ruby-changes:50658] usa:r62821 (ruby_2_3): merge revision(s) 60055: [Backport #13856]
usa 2018-03-19 00:07:24 +0900 (Mon, 19 Mar 2018) New Revision: 62821 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62821 Log: merge revision(s) 60055: [Backport #13856] io.c: fix segfault with closing socket on Windows * io.c (fptr_finalize_flush): add an argument to keep GVL. * io.c (fptr_finalize): adjust for above change. * io.c (io_close_fptr): closing without GVL causes another exception while raising exception in another thread. This causes segfault on Windows. Keep GVL while closing when another thread raises. [Bug #13856] [ruby-core:82602] Modified directories: branches/ruby_2_3/ Modified files: branches/ruby_2_3/ChangeLog branches/ruby_2_3/io.c branches/ruby_2_3/version.h Index: ruby_2_3/version.h =================================================================== --- ruby_2_3/version.h (revision 62820) +++ ruby_2_3/version.h (revision 62821) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1 #define RUBY_VERSION "2.3.7" #define RUBY_RELEASE_DATE "2018-03-19" -#define RUBY_PATCHLEVEL 421 +#define RUBY_PATCHLEVEL 422 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 3 Index: ruby_2_3/ChangeLog =================================================================== --- ruby_2_3/ChangeLog (revision 62820) +++ ruby_2_3/ChangeLog (revision 62821) @@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1 +Mon Mar 19 00:06:43 2018 Hiroshi Shirosaki <h.shirosaki@g...> + + io.c: fix segfault with closing socket on Windows + + * io.c (fptr_finalize_flush): add an argument to keep GVL. + + * io.c (fptr_finalize): adjust for above change. + + * io.c (io_close_fptr): closing without GVL causes another exception + while raising exception in another thread. This causes segfault on + Windows. Keep GVL while closing when another thread raises. + [Bug #13856] + Mon Mar 19 00:04:08 2018 Nobuyoshi Nakada <nobu@r...> * lib/forwardable.rb (_delegator_method): leave the backtrace Index: ruby_2_3/io.c =================================================================== --- ruby_2_3/io.c (revision 62820) +++ ruby_2_3/io.c (revision 62821) @@ -4202,7 +4202,7 @@ static void free_io_buffer(rb_io_buffer_ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/io.c#L4202 static void clear_codeconv(rb_io_t *fptr); static void -fptr_finalize_flush(rb_io_t *fptr, int noraise) +fptr_finalize_flush(rb_io_t *fptr, int noraise, int keepgvl) { VALUE err = Qnil; int fd = fptr->fd; @@ -4250,7 +4250,7 @@ fptr_finalize_flush(rb_io_t *fptr, int n https://github.com/ruby/ruby/blob/trunk/ruby_2_3/io.c#L4250 * We assumes it is closed. */ /**/ - int keepgvl = !(mode & FMODE_WRITABLE); + keepgvl |= !(mode & FMODE_WRITABLE); keepgvl |= noraise; if ((maygvl_close(fd, keepgvl) < 0) && NIL_P(err)) err = noraise ? Qtrue : INT2NUM(errno); @@ -4271,7 +4271,7 @@ fptr_finalize_flush(rb_io_t *fptr, int n https://github.com/ruby/ruby/blob/trunk/ruby_2_3/io.c#L4271 static void fptr_finalize(rb_io_t *fptr, int noraise) { - fptr_finalize_flush(fptr, noraise); + fptr_finalize_flush(fptr, noraise, FALSE); free_io_buffer(&fptr->rbuf); free_io_buffer(&fptr->wbuf); clear_codeconv(fptr); @@ -4351,6 +4351,13 @@ rb_io_memsize(const rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/io.c#L4351 return size; } +#ifdef _WIN32 +/* keep GVL while closing to prevent crash on Windows */ +# define KEEPGVL TRUE +#else +# define KEEPGVL FALSE +#endif + int rb_notify_fd_close(int fd); static rb_io_t * io_close_fptr(VALUE io) @@ -4375,8 +4382,8 @@ io_close_fptr(VALUE io) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/io.c#L4382 fd = fptr->fd; busy = rb_notify_fd_close(fd); - fptr_finalize_flush(fptr, FALSE); if (busy) { + fptr_finalize_flush(fptr, FALSE, KEEPGVL); do rb_thread_schedule(); while (rb_notify_fd_close(fd)); } rb_io_fptr_cleanup(fptr, FALSE); Index: ruby_2_3 =================================================================== --- ruby_2_3 (revision 62820) +++ ruby_2_3 (revision 62821) Property changes on: ruby_2_3 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r60055 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/