diff --git a/spec/std/socket/socket_spec.cr b/spec/std/socket/socket_spec.cr index ba6e1c4684d5..0b0ef93a73eb 100644 --- a/spec/std/socket/socket_spec.cr +++ b/spec/std/socket/socket_spec.cr @@ -88,7 +88,8 @@ describe Socket, tags: "network" do expect_raises(IO::TimeoutError) { server.accept } expect_raises(IO::TimeoutError) { server.accept? } - server.close + ensure + server.try &.close end it "sends messages" do diff --git a/spec/std/socket/udp_socket_spec.cr b/spec/std/socket/udp_socket_spec.cr index 3f8e46ac3d4c..1f8530ff9047 100644 --- a/spec/std/socket/udp_socket_spec.cr +++ b/spec/std/socket/udp_socket_spec.cr @@ -28,7 +28,8 @@ describe UDPSocket, tags: "network" do socket = UDPSocket.new(family) socket.bind(address, 0) socket.local_address.address.should eq address - socket.close + ensure + socket.try &.close end it "sends and receives messages" do