Issue #13158 has been updated by Nobuyoshi Nakada.

Description updated
Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED

----------------------------------------
Bug #13158: UNIXServer#closed? returns false after UNIXServer#close called
https://bugs.ruby-lang.org/issues/13158#change-62681

* Author: Satoshi TAGOMORI
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0dev (2017-01-25 trunk 57420) [x86_64-linux]
* Backport: 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED
----------------------------------------
When I tried the simple script below, ruby trunk works unexpectedly:

```ruby
require 'socket'

server = UNIXServer.new('/tmp/yaaaay')
thread = Thread.new do
  begin
    while sock = server.accept
      p(here: "accepted", sock: sock)
      sock.close rescue nil
    end
  rescue => e
    p(here: "rescue", closed: server.closed?, error: e)
  end
end

sleep 1
server.close
sleep 1
File.delete('/tmp/yaaaay')
```

The output of this script is:

```
# ruby 2.5.0-dev on linux
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ruby -v
ruby 2.5.0dev (2017-01-25 trunk 57420) [x86_64-linux]
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ruby hoge.rb 
{:here=>"rescue", :closed=>false, :error=>#<IOError: stream closed>}

# ruby 2.4.0 on linux
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ ruby hoge.rb 
{:here=>"rescue", :closed=>true, :error=>#<IOError: stream closed>}

# ruby 2.5.0-dev on osx
MBA:fluentd tagomoris$ ruby -v
ruby 2.5.0dev (2017-01-24 trunk 57413) [x86_64-darwin15]
MBA:fluentd tagomoris$ ruby hoge.rb 
{:here=>"rescue", :closed=>true, :error=>#<Errno::EBADF: Bad file descriptor>}

# full list I tried is here: https://gist.github.com/tagomoris/5bc1b618c5196c693a7b096353eb57e4
```

Raised error class is not mine point. This script with ruby 2.5.0-dev on linux returns false for `server.closed?`.
When any errors are raised, we should check whether it's raised by intentional `sever.close` or not. But it doesn't work well on ruby 2.5.0 on linux.

Is it possible to fix this problem?

Note: When I added some more `p(here: "rescue", closed: server.closed?)` lines in rescue clause, these (2nd and later) puts "true".



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>