Skip to content

Commit 5b579ad

Browse files
committed
Improve connection&.close handling.
1 parent 212e708 commit 5b579ad

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/async/websocket/adapters/http.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def self.open(request, headers: [], protocols: [], handler: Connection, extensio
3939
connection = handler.call(framer, protocol, extensions)
4040

4141
yield connection
42-
43-
connection.close unless connection.closed?
42+
ensure
43+
connection&.close
44+
stream.close
4445
end
4546

4647
# Once we get to this point, we no longer need to hold on to the request:

lib/async/websocket/client.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ def self.connect(endpoint, *arguments, **options, &block)
6262

6363
begin
6464
yield connection
65+
6566
ensure
66-
connection.close
67-
client.close
67+
connection&.close
68+
client&.close
6869
end
6970
end
7071
end

0 commit comments

Comments
 (0)