소스 검색

refinery: acquire exclusive lock on greylist before refining

Modifications to the greylist (appending or deleting from) are dangerous while the refinery is ongoing, since it can lead to panics in the case the refinery fails (because we delete from the greylist by index when that happens).

We mitigate this issue by acquiring an exclusive lock on the greylist before proceeding with the refinery, and dropping the lock once the refinery process has finished and greylist modifications are no longer dangerous.
draoi 2 년 전
부모
커밋
7ff45ea2a5
1개의 변경된 파일2개의 추가작업 그리고 3개의 파일을 삭제
  1. 2 3
      src/net/session/refine_session.rs

+ 2 - 3
src/net/session/refine_session.rs

@@ -250,9 +250,8 @@ impl GreylistRefinery {
                     }
 
                     // Freeze the greylist in this state. Necessary since the greylist
-                    // can be modified by `hosts::move_host()`.
-                    let mut greylist =
-                        hosts.container.hostlists[HostColor::Grey as usize].write().await;
+                    // can be modified by `hosts::move_host()` or `hosts::store()`.
+                    let mut greylist = hosts.container.hostlists[HostColor::Grey as usize].write().await;
 
                     if !self.session().handshake_node(url.clone(), self.p2p().clone()).await {
                         greylist.remove(position);