Skip to content
Permalink
Browse files
Fix socket initialization (#5059)
Socket initialization (TCPSocket at least) uses Addrinfo.tcp which may retry and call Socket#initialize, leaving inconsistent state since the socket is tracked as closed
  • Loading branch information
bcardiff committed Oct 2, 2017
1 parent 37d4448 commit b83089945ae5f5abe6f7a100734d4cd55bc1b078
Showing 1 changed file with 3 additions and 1 deletion.
@@ -42,7 +42,7 @@ class Socket
@read_event : Event::Event?
@write_event : Event::Event?

@closed = false
@closed : Bool

getter family : Family
getter type : Type
@@ -67,6 +67,7 @@ class Socket
end

def initialize(@family, @type, @protocol = Protocol::IP, blocking = false)
@closed = false
fd = LibC.socket(family, type, protocol)
raise Errno.new("failed to create socket:") if fd == -1
init_close_on_exec(fd)
@@ -79,6 +80,7 @@ class Socket
end

protected def initialize(@fd : Int32, @family, @type, @protocol = Protocol::IP, blocking = false)
@closed = false
init_close_on_exec(@fd)

self.sync = true

0 comments on commit b830899

Please sign in to comment.