Project

General

Profile

Actions

Bug #13158

closed

UNIXServer#closed? returns false after UNIXServer#close called

Added by tagomoris (Satoshi Tagomori) almost 8 years ago. Updated over 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0dev (2017-01-25 trunk 57420) [x86_64-linux]
[ruby-core:79262]

Description

When I tried the simple script below, ruby trunk works unexpectedly:

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".


Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #13076: SEGV in io.c when reading closed stream in ThreadClosednobu (Nobuyoshi Nakada)Actions
Related to Ruby master - Bug #13405: IO#close raises "stream closed"ClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0