Skip to content

AddrInfo.foreach connects to every addr #35

@cthulhuology

Description

@cthulhuology

When running the sample:

s = TCPSocket.open("www.kame.net", 80)
s.write("GET / HTTP/1.0\r\n\r\n")
puts s.read
s.close

The AddrInfo.foreach on line 236 here https://github.com/iij/mruby-socket/blob/master/mrblib/socket.rb#L236 will always evalute the block for each address returned. On Slackware 14.2,
the getaddrinfo call is currently returning an array of 6 addresses for www.kame.net, and will
attempt to connect to each of those 6 addresses.

After creating multiple sockets (opening multiple fds and connecting to each addr, it then will raise SocketError (because the return on 247 only leaves the local block, not the top level block).

to fix this the top level each should break as soon as one address succeeds, and the error should not be raised after the block, unless the error was set by one of the socket operations caught by rescue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions