Skip to content

Commit 64aa809

Browse files
author
hhaensel
committed
fix subscription error: move unsubscribe_disconnected_clients() after push_subscription()
1 parent 5105f5c commit 64aa809

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

src/WebChannels.jl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ end
8383
Subscribes a web socket client `ws` to `channel`.
8484
"""
8585
function subscribe(ws::HTTP.WebSockets.WebSocket, channel::ChannelName) :: ChannelClientsCollection
86-
# Clean up stale entries from previous connections on this channel so that
87-
# disconnected clients (and their handler tasks) do not accumulate on reconnect.
88-
unsubscribe_disconnected_clients(channel)
89-
9086
if haskey(CLIENTS, id(ws))
9187
in(channel, CLIENTS[id(ws)].channels) || push!(CLIENTS[id(ws)].channels, channel)
9288
else
@@ -95,6 +91,10 @@ function subscribe(ws::HTTP.WebSockets.WebSocket, channel::ChannelName) :: Chann
9591

9692
push_subscription(id(ws), channel)
9793

94+
# Clean up stale entries from previous connections on this channel so that
95+
# disconnected clients (and their handler tasks) do not accumulate on reconnect.
96+
unsubscribe_disconnected_clients(channel)
97+
9898
@debug "Subscribed: $(id(ws)) ($(Dates.now()))"
9999
CLIENTS
100100
end
@@ -245,10 +245,6 @@ function broadcast(channels::Union{ChannelName,Vector{ChannelName}},
245245

246246
@async unsubscribe_disconnected_clients() |> errormonitor
247247

248-
# @show channels
249-
# @show CLIENTS
250-
251-
# try
252248
for channel in channels
253249
if ! haskey(SUBSCRIPTIONS, channel)
254250
unsubscribe_disconnected_clients(channel)
@@ -276,9 +272,6 @@ function broadcast(channels::Union{ChannelName,Vector{ChannelName}},
276272
end
277273
end
278274
end
279-
# catch ex
280-
# @warn ex
281-
# end
282275

283276
true
284277
end

0 commit comments

Comments
 (0)