Fixed a regression when updating config messages

Doing a config push was working via `Atomic.wrappedValue` instead of `Atomic.mutate` - we need to use `Atomic.mutate` in this case because we want to block other threads from modifying the config while we are doing a push (otherwise it can crash due to data changing while generating the push payload)
pull/1018/head
Morgan Pretty 8 months ago
parent 31e5719318
commit d38e620e8e

@ -229,70 +229,70 @@ public extension LibSession {
/// config while we are reading (which could result in crashes) /// config while we are reading (which could result in crashes)
return try existingDumpVariants return try existingDumpVariants
.reduce(into: PendingChanges()) { result, variant in .reduce(into: PendingChanges()) { result, variant in
guard try dependencies.caches[.libSession]
let conf = dependencies.caches[.libSession] .config(for: variant, publicKey: publicKey)
.config(for: variant, publicKey: publicKey) .mutate { conf in
.wrappedValue guard conf != nil else { return }
else { return }
// Check if the config needs to be pushed
// Check if the config needs to be pushed guard config_needs_push(conf) else {
guard config_needs_push(conf) else { // If not then try retrieve any obsolete hashes to be removed
// If not then try retrieve any obsolete hashes to be removed guard let cObsoletePtr: UnsafeMutablePointer<config_string_list> = config_old_hashes(conf) else {
guard let cObsoletePtr: UnsafeMutablePointer<config_string_list> = config_old_hashes(conf) else { return
return }
}
let obsoleteHashes: [String] = [String](
let obsoleteHashes: [String] = [String]( pointer: cObsoletePtr.pointee.value,
pointer: cObsoletePtr.pointee.value, count: cObsoletePtr.pointee.len,
count: cObsoletePtr.pointee.len, defaultValue: []
defaultValue: [] )
)
// If there are no obsolete hashes then no need to return anything
// If there are no obsolete hashes then no need to return anything guard !obsoleteHashes.isEmpty else { return }
guard !obsoleteHashes.isEmpty else { return }
result.append(hashes: obsoleteHashes)
result.append(hashes: obsoleteHashes) return
return }
}
guard let cPushData: UnsafeMutablePointer<config_push_data> = config_push(conf) else {
guard let cPushData: UnsafeMutablePointer<config_push_data> = config_push(conf) else { let configCountInfo: String = {
let configCountInfo: String = { switch variant {
switch variant { case .userProfile: return "1 profile" // stringlint:disable
case .userProfile: return "1 profile" // stringlint:disable case .contacts: return "\(contacts_size(conf)) contacts" // stringlint:disable
case .contacts: return "\(contacts_size(conf)) contacts" // stringlint:disable case .userGroups: return "\(user_groups_size(conf)) group conversations" // stringlint:disable
case .userGroups: return "\(user_groups_size(conf)) group conversations" // stringlint:disable case .convoInfoVolatile: return "\(convo_info_volatile_size(conf)) volatile conversations" // stringlint:disable
case .convoInfoVolatile: return "\(convo_info_volatile_size(conf)) volatile conversations" // stringlint:disable case .invalid: return "Invalid" // stringlint:disable
case .invalid: return "Invalid" // stringlint:disable }
}()
throw LibSessionError(
conf,
fallbackError: .unableToGeneratePushData,
logMessage: "[LibSession] Failed to generate push data for \(variant) config data, size: \(configCountInfo), error"
)
} }
}()
throw LibSessionError( let pushData: Data = Data(
conf, bytes: cPushData.pointee.config,
fallbackError: .unableToGeneratePushData, count: cPushData.pointee.config_len
logMessage: "[LibSession] Failed to generate push data for \(variant) config data, size: \(configCountInfo), error" )
) let obsoleteHashes: [String] = [String](
} pointer: cPushData.pointee.obsolete,
count: cPushData.pointee.obsolete_len,
let pushData: Data = Data( defaultValue: []
bytes: cPushData.pointee.config, )
count: cPushData.pointee.config_len let seqNo: Int64 = cPushData.pointee.seqno
) cPushData.deallocate()
let obsoleteHashes: [String] = [String](
pointer: cPushData.pointee.obsolete, result.append(
count: cPushData.pointee.obsolete_len, data: PendingChanges.PushData(
defaultValue: [] data: pushData,
) seqNo: seqNo,
let seqNo: Int64 = cPushData.pointee.seqno variant: variant
cPushData.deallocate() ),
hashes: obsoleteHashes
result.append( )
data: PendingChanges.PushData( }
data: pushData,
seqNo: seqNo,
variant: variant
),
hashes: obsoleteHashes
)
} }
} }

Loading…
Cancel
Save