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 #1

Updated by nobu (Nobuyoshi Nakada) almost 8 years ago

  • Related to Bug #13076: SEGV in io.c when reading closed stream in Thread added

Updated by nobu (Nobuyoshi Nakada) almost 8 years ago

  • Description updated (diff)
  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED
Actions #3

Updated by nobu (Nobuyoshi Nakada) almost 8 years ago

  • Status changed from Open to Closed

Applied in changeset r57422.


io.c: close before wait

  • io.c (io_close_fptr): notify then close, and wait for other
    threads before free fptr. [ruby-core:79262] [Bug #13158]

Updated by naruse (Yui NARUSE) over 7 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE

ruby_2_4 r57872 merged revision(s) 57422.

Updated by usa (Usaku NAKAMURA) over 7 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE to 2.2: DONE, 2.3: REQUIRED, 2.4: DONE

ruby_2_2 r58094 merged revision(s) 57422.

Updated by nagachika (Tomoyuki Chikanaga) over 7 years ago

  • Backport changed from 2.2: DONE, 2.3: REQUIRED, 2.4: DONE to 2.2: DONE, 2.3: DONE, 2.4: DONE

ruby_2_3 r58177 merged revision(s) 57422.

Actions #7

Updated by shyouhei (Shyouhei Urabe) over 7 years ago

  • Related to Bug #13405: IO#close raises "stream closed" added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0