[ruby-list:50664] Re: OSXのNet::HTTPResponse の bodyについて

From: Kazuhiro NISHIYAMA <zn@...>
Date: 2018-05-15 11:56:06 UTC
List: ruby-list #50664
西山和広です。

On Tue, 15 May 2018 14:46:34 +0900,
nst wrote:

> test.rb:13:in `write': Invalid argument @ io_write - dum (Errno::EINVAL)
> 
> #このエラーを見てres.bodyがおかしいと気がつくのにかなり時間がかかりました

write で 2GiB以上だと EINVAL になっているだけのようなので、
res.body 自体は正常なのではないでしょうか。

$ cat test.rb
open("test.txt", "wb") do |f|
  f.write("x"*(2*1024*1024*1024))
end
$ ruby test.rb
Traceback (most recent call last):
	3: from test.rb:1:in `<main>'
	2: from test.rb:1:in `open'
	1: from test.rb:2:in `block in <main>'
test.rb:2:in `write': Invalid argument @ io_write - test.txt (Errno::EINVAL)
$ cat test2.rb
open("test.txt", "wb") do |f|
  f.write("x"*(2*1024*1024*1024-1))
end
$ ruby test2.rb
$

> Ubuntu 16.04では、NoMemoryErrorとなったのでOSX限定??
> $ ruby2.5 ./test.rb 
> Traceback (most recent call last):
> ./test.rb: failed to allocate memory (NoMemoryError)

Ubuntu 16.04 だと 2GiB の String を作ろうとした時点で NoMemoryError に
なるようなので、別の話のようです。

$ ruby -e '"x"*(2*1024*1024*1024)'
Traceback (most recent call last):
-e: failed to allocate memory (NoMemoryError)

-- 
|ZnZ(ゼット エヌ ゼット)
|西山和広(Kazuhiro NISHIYAMA)

In This Thread