Skip to content
This repository was archived by the owner on Aug 29, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/async/io/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def self.connect(remote_address, local_address = nil, reuse_port: false, task: T
begin
wrapper.connect(remote_address.to_sockaddr)
task.annotate "connected to #{remote_address.inspect}"
rescue
rescue Exception
wrapper.close
raise
end
Expand Down
10 changes: 10 additions & 0 deletions spec/async/io/socket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
Async::IO::Socket.connect(address)
end.to raise_error(Errno::ECONNREFUSED)
end

it "should close the socket when interrupted by a timeout" do
wrapper = double()
expect(Async::IO::Socket).to receive(:build).and_return(wrapper)
expect(wrapper).to receive(:connect).and_raise Async::TimeoutError
expect(wrapper).to receive(:close)
expect do
Async::IO::Socket.connect(address)
end.to raise_error(Async::TimeoutError)
end
end

describe '#bind' do
Expand Down