Skip to content

Commit c6a25f3

Browse files
committed
Merge branch 'fix/close-ensure-socket'
* fix/close-ensure-socket: - socket: rescue transmit in close without logging Ensure socket is closed even when transmit raises in Connection#close
2 parents 148072a + 4e6da79 commit c6a25f3

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby-4.0.5

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## main
44

5+
- Tolerate `#transmit` errors on `socket.close`.
6+
57
## 0.3.3
68

79
- Sync with upstream (Rails 8.2.0.alpha).

lib/action_cable/connection/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def close(reason: nil, reconnect: true)
133133
type: ActionCable::INTERNAL[:message_types][:disconnect],
134134
reason: reason,
135135
reconnect: reconnect
136-
)
136+
) rescue nil
137137
socket.close
138138
end
139139

test/connection/base_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ def disconnect
6464
end
6565
end
6666

67+
test "socket is closed even when transmit raises during close" do
68+
connection = open_connection
69+
socket = connection.socket
70+
71+
# Simulate a socket whose output queue has already been closed (e.g. after a
72+
# prior restart call), so that transmitting the disconnect message raises.
73+
socket.stub(:transmit, ->(*) { raise ClosedQueueError, "queue closed" }) do
74+
assert_called(socket, :close) do
75+
connection.close(reason: "server_restart")
76+
end
77+
end
78+
end
79+
6780
test "#broadcast" do
6881
connection = Connection.new(ActionCable.server, ActionCable::Server::Socket.new(ActionCable.server, {}))
6982

0 commit comments

Comments
 (0)