Skip to content

Commit 71aa8d0

Browse files
committed
fix: [torrust#1491] deadlock running tests
I don't know why it was not happening before. The previous changes only: - Remove types aliases. - Remove generics. - Remove unused traits. However the concrete type for the repository should be the same after monomorphization.
1 parent f106c01 commit 71aa8d0

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/torrent-repository/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal
2323
torrust-tracker-clock = { version = "3.0.0-develop", path = "../clock" }
2424
torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" }
2525
torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" }
26+
tracing = "0"
2627

2728
[dev-dependencies]
2829
async-std = { version = "1", features = ["attributes", "tokio1"] }

packages/torrent-repository/src/repository.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ impl TorrentsSkipMapMutexStd {
4242
opt_persistent_torrent: Option<PersistentTorrent>,
4343
) -> bool {
4444
if let Some(existing_entry) = self.torrents.get(info_hash) {
45+
tracing::debug!("Torrent already exists: {:?}", info_hash);
46+
4547
existing_entry
4648
.value()
4749
.lock()
4850
.expect("can't acquire lock for torrent entry")
4951
.upsert_peer(peer)
5052
} else {
53+
tracing::debug!("Inserting new torrent: {:?}", info_hash);
54+
5155
let new_entry = if let Some(number_of_downloads) = opt_persistent_torrent {
5256
EntryMutexStd::new(
5357
Torrent {
@@ -62,13 +66,9 @@ impl TorrentsSkipMapMutexStd {
6266

6367
let inserted_entry = self.torrents.get_or_insert(*info_hash, new_entry);
6468

65-
let number_of_downloads_increased = inserted_entry
66-
.value()
67-
.lock()
68-
.expect("can't acquire lock for torrent entry")
69-
.upsert_peer(peer);
69+
let mut torrent_guard = inserted_entry.value().lock().expect("can't acquire lock for torrent entry");
7070

71-
number_of_downloads_increased
71+
torrent_guard.upsert_peer(peer)
7272
}
7373
}
7474

packages/tracker-core/src/torrent/repository/in_memory.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -528,20 +528,17 @@ mod tests {
528528
#[allow(clippy::from_over_into)]
529529
impl Into<TorrentEntryInfo> for TorrentEntry {
530530
fn into(self) -> TorrentEntryInfo {
531-
TorrentEntryInfo {
532-
swarm_metadata: self
533-
.lock()
534-
.expect("can't acquire lock for torrent entry")
535-
.get_swarm_metadata(),
536-
peers: self
537-
.lock()
538-
.expect("can't acquire lock for torrent entry")
539-
.get_peers(None)
540-
.iter()
541-
.map(|peer| *peer.clone())
542-
.collect(),
543-
number_of_peers: self.lock().expect("can't acquire lock for torrent entry").get_peers_len(),
544-
}
531+
let torrent_guard = self.lock().expect("can't acquire lock for torrent entry");
532+
533+
let torrent_entry_info = TorrentEntryInfo {
534+
swarm_metadata: torrent_guard.get_swarm_metadata(),
535+
peers: torrent_guard.get_peers(None).iter().map(|peer| *peer.clone()).collect(),
536+
number_of_peers: torrent_guard.get_peers_len(),
537+
};
538+
539+
drop(torrent_guard);
540+
541+
torrent_entry_info
545542
}
546543
}
547544

packages/tracker-core/src/torrent/services.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,12 @@ pub fn get_torrents(in_memory_torrent_repository: &Arc<InMemoryTorrentRepository
190190
let mut basic_infos: Vec<BasicInfo> = vec![];
191191

192192
for info_hash in info_hashes {
193-
if let Some(stats) = in_memory_torrent_repository
194-
.get(info_hash)
195-
.map(|t| t.lock().expect("can't acquire lock for torrent entry").get_swarm_metadata())
196-
{
193+
if let Some(stats) = in_memory_torrent_repository.get(info_hash).map(|torrent_entry| {
194+
torrent_entry
195+
.lock()
196+
.expect("can't acquire lock for torrent entry")
197+
.get_swarm_metadata()
198+
}) {
197199
basic_infos.push(BasicInfo {
198200
info_hash: *info_hash,
199201
seeders: u64::from(stats.complete),

0 commit comments

Comments
 (0)