Skip to content

Commit

Permalink
Fix socket initialization (#5059)
Browse files Browse the repository at this point in the history
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
bcardiff authored Oct 2, 2017
1 parent 37d4448 commit b830899
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/socket.cr
Original file line number Diff line number Diff line change
@@ -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.