ruby-changes:53874
From: normal <ko1@a...>
Date: Fri, 30 Nov 2018 05:00:11 +0900 (JST)
Subject: [ruby-changes:53874] normal:r66093 (trunk): disable non-blocking pipes and sockets by default
normal 2018-11-30 05:00:00 +0900 (Fri, 30 Nov 2018) New Revision: 66093 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66093 Log: disable non-blocking pipes and sockets by default There seems to be a compatibility problems with Rails + Rack::Deflater; so we revert this incompatibility. This effectively reverts r65922; but keeps the bugfixes to better support non-blocking sockets and pipes for future use. [Bug #15356] [Bug #14968] Modified files: trunk/ext/socket/init.c trunk/ext/socket/rubysocket.h trunk/ext/socket/socket.c trunk/io.c trunk/test/socket/test_basicsocket.rb Index: io.c =================================================================== --- io.c (revision 66092) +++ io.c (revision 66093) @@ -138,7 +138,8 @@ off_t __syscall(quad_t number, ...); https://github.com/ruby/ruby/blob/trunk/io.c#L138 #if defined(_WIN32) # define RUBY_PIPE_NONBLOCK_DEFAULT (0) #elif defined(O_NONBLOCK) -# define RUBY_PIPE_NONBLOCK_DEFAULT (O_NONBLOCK) + /* disabled for [Bug #15356] (Rack::Deflater + rails) failure: */ +# define RUBY_PIPE_NONBLOCK_DEFAULT (0) #else /* any platforms where O_NONBLOCK does not exist? */ # define RUBY_PIPE_NONBLOCK_DEFAULT (0) #endif Index: ext/socket/rubysocket.h =================================================================== --- ext/socket/rubysocket.h (revision 66092) +++ ext/socket/rubysocket.h (revision 66093) @@ -32,7 +32,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/socket/rubysocket.h#L32 */ # define RSOCK_NONBLOCK_DEFAULT (0) #else -# define RSOCK_NONBLOCK_DEFAULT (1) +# define RSOCK_NONBLOCK_DEFAULT (0) # include <sys/socket.h> # include <netinet/in.h> # ifdef HAVE_NETINET_IN_SYSTM_H Index: ext/socket/init.c =================================================================== --- ext/socket/init.c (revision 66092) +++ ext/socket/init.c (revision 66093) @@ -435,7 +435,7 @@ rsock_socket0(int domain, int type, int https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L435 static int cloexec_state = -1; /* <0: unknown, 0: ignored, >0: working */ if (cloexec_state > 0) { /* common path, if SOCK_CLOEXEC is defined */ - ret = socket(domain, type|SOCK_CLOEXEC|SOCK_NONBLOCK, proto); + ret = socket(domain, type|SOCK_CLOEXEC|RSOCK_NONBLOCK_DEFAULT, proto); if (ret >= 0) { if (ret <= 2) goto fix_cloexec; @@ -443,7 +443,7 @@ rsock_socket0(int domain, int type, int https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L443 } } else if (cloexec_state < 0) { /* usually runs once only for detection */ - ret = socket(domain, type|SOCK_CLOEXEC|SOCK_NONBLOCK, proto); + ret = socket(domain, type|SOCK_CLOEXEC|RSOCK_NONBLOCK_DEFAULT, proto); if (ret >= 0) { cloexec_state = rsock_detect_cloexec(ret); if (cloexec_state == 0 || ret <= 2) Index: ext/socket/socket.c =================================================================== --- ext/socket/socket.c (revision 66092) +++ ext/socket/socket.c (revision 66093) @@ -175,16 +175,17 @@ rsock_socketpair0(int domain, int type, https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L175 { int ret; static int cloexec_state = -1; /* <0: unknown, 0: ignored, >0: working */ + static const int default_flags = SOCK_CLOEXEC|RSOCK_NONBLOCK_DEFAULT; if (cloexec_state > 0) { /* common path, if SOCK_CLOEXEC is defined */ - ret = socketpair(domain, type|SOCK_CLOEXEC|SOCK_NONBLOCK, protocol, sv); + ret = socketpair(domain, type|default_flags, protocol, sv); if (ret == 0 && (sv[0] <= 2 || sv[1] <= 2)) { goto fix_cloexec; /* highly unlikely */ } goto update_max_fd; } else if (cloexec_state < 0) { /* usually runs once only for detection */ - ret = socketpair(domain, type|SOCK_CLOEXEC|SOCK_NONBLOCK, protocol, sv); + ret = socketpair(domain, type|default_flags, protocol, sv); if (ret == 0) { cloexec_state = rsock_detect_cloexec(sv[0]); if ((cloexec_state == 0) || (sv[0] <= 2 || sv[1] <= 2)) Index: test/socket/test_basicsocket.rb =================================================================== --- test/socket/test_basicsocket.rb (revision 66092) +++ test/socket/test_basicsocket.rb (revision 66093) @@ -159,8 +159,8 @@ class TestSocket_BasicSocket < Test::Uni https://github.com/ruby/ruby/blob/trunk/test/socket/test_basicsocket.rb#L159 set_nb = true buf = String.new if ssock.respond_to?(:nonblock?) - assert_predicate(ssock, :nonblock?) - assert_predicate(csock, :nonblock?) + assert_not_predicate(ssock, :nonblock?) + assert_not_predicate(csock, :nonblock?) csock.nonblock = ssock.nonblock = false # Linux may use MSG_DONTWAIT to avoid setting O_NONBLOCK -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/