Project

General

Profile

Actions

Backport #4132

closed

Socket.close attempting to close the socket twice

Added by devmod (Claudio Villalobos) over 13 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
[ruby-core:33628]

Description

=begin
Socket.close calls shutdown twice on the same file descriptor

socktest.rb

require 'socket'
include Socket::Constants
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )
socket.bind( sockaddr )
socket.listen( 5 )
puts "socket.to_i: #{socket.to_i}"
socket.close
#############

$ strace -e trace=open,close ruby1.8 socktest.rb
...
socket.to_i: 3
close(3) = 0
close(3) = -1 EBADF (Bad file descriptor)


socket.c

socks_s_close(sock)
...
1386 shutdown(fileno(fptr->f), 2);
1387 shutdown(fileno(fptr->f2), 2);
=end

Actions #1

Updated by matz (Yukihiro Matsumoto) over 13 years ago

=begin
Hi,

In message "Re: [ruby-core:33628] [Ruby 1.8-Bug#4132][Open] Socket.close attempting to close the socket twice"
on Wed, 8 Dec 2010 07:57:58 +0900, Claudio Villalobos writes:

|Bug #4132: Socket.close attempting to close the socket twice
|http://redmine.ruby-lang.org/issues/show/4132
|
|Author: Claudio Villalobos
|Status: Open, Priority: Normal
|Category: ext
|ruby -v: ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
|
|Socket.close calls shutdown twice on the same file descriptor

Ruby 1.8 creates two FILE* streams on a socket to implement
bidirectional communication. Two calls to close(2) is a side effect.
Since it shouldn't do any harm, we don't consider it a bug. Tell us
if it would cause any trouble (other than one useless system call, and
a failure in strace log).

						matz.

=end

Actions #2

Updated by devmod (Claudio Villalobos) over 13 years ago

=begin
Hi,

Since file descriptors are reused after closing, wouldn't there be an edge case where that file descriptor could have been assigned to another socket before the second close had been executed?

=end

Actions #3

Updated by matz (Yukihiro Matsumoto) over 13 years ago

=begin
Hi,

In message "Re: [ruby-core:33630] [Ruby 1.8-Bug#4132] Socket.close attempting to close the socket twice"
on Wed, 8 Dec 2010 10:18:22 +0900, Claudio Villalobos writes:
|
|Since file descriptors are reused after closing, wouldn't there be an edge case where that file descriptor could have been assigned to another socket before the second close had been executed?

On 1.8 (and mostly on 1.9 too), the execution is protected from
multithreading, so that we don't have to worry about concurrency here.

						matz.

=end

Actions #4

Updated by devmod (Claudio Villalobos) over 13 years ago

=begin
Understood. Thanks
=end

Actions #5

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby 1.8 to Backport187
  • Description updated (diff)
  • Status changed from Open to Closed
  • ruby -v deleted (ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux])
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0