mirror of
git://jb55.com/damus
synced 2024-09-18 19:23:49 +00:00
fix: endless connection attempt loop after user removes relay
This patch fixes an issue where, after the user removes a misbehaving relay, the RelayConnection will keep trying to reconnect endlessly. You can reproduce the issue prior to this change by adding the relay wss://brb.io. It will fail to connect over and over. Then remove the relay in the UI. In the console, you will see that it keeps trying to connect, and the corresponding RelayConnection never gets deallocated. After the change, it stops connecting and deallocates the RelayConnection. Changelog-Fixed: endless connection attempt loop after user removes relay Signed-off-by: Bryan Montz <bryanmontz@me.com> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
593d0e2abe
commit
4fecf72963
@ -40,6 +40,7 @@ public struct RelayURL: Hashable {
|
||||
final class RelayConnection: ObservableObject {
|
||||
@Published private(set) var isConnected = false
|
||||
@Published private(set) var isConnecting = false
|
||||
private var isDisabled = false
|
||||
|
||||
private(set) var last_connection_attempt: TimeInterval = 0
|
||||
private(set) var last_pong: Date? = nil
|
||||
@ -57,7 +58,11 @@ final class RelayConnection: ObservableObject {
|
||||
}
|
||||
|
||||
func ping() {
|
||||
socket.ping { err in
|
||||
socket.ping { [weak self] err in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
self.last_pong = .now
|
||||
self.log?.add("Successful ping")
|
||||
@ -103,6 +108,10 @@ final class RelayConnection: ObservableObject {
|
||||
isConnecting = false
|
||||
}
|
||||
|
||||
func disablePermanently() {
|
||||
isDisabled = true
|
||||
}
|
||||
|
||||
func send_raw(_ req: String) {
|
||||
socket.send(.string(req))
|
||||
}
|
||||
@ -168,8 +177,8 @@ final class RelayConnection: ObservableObject {
|
||||
}
|
||||
|
||||
func reconnect() {
|
||||
guard !isConnecting else {
|
||||
return // we're already trying to connect
|
||||
guard !isConnecting && !isDisabled else {
|
||||
return // we're already trying to connect or we're disabled
|
||||
}
|
||||
disconnect()
|
||||
connect()
|
||||
|
@ -95,6 +95,7 @@ class RelayPool {
|
||||
|
||||
for relay in relays {
|
||||
if relay.id == relay_id {
|
||||
relay.connection.disablePermanently()
|
||||
relays.remove(at: i)
|
||||
break
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user