Skip to content

Commit 61b14c5

Browse files
committed
fix(gateway): fix nat mapping resolution mismatch during cache eviction
During async cache eviction by moka, mapping temporary contains orphaned entries. Changing Nat::find() to gracefully reconstruct the SessionKey from mapping resolves lookup misses bridging the eviction gap interval.
1 parent 769c73b commit 61b14c5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/gateway/nat.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,20 @@ impl Nat {
123123
}
124124

125125
pub async fn find(&self, nat_port: u16) -> Option<Session> {
126-
if let Some(addr_key) = self.get_addr_key_by_port_fast(&nat_port).await
127-
&& let Some(session) = self.cache.get(&addr_key).await
128-
{
129-
return Some(*session);
126+
if let Some(addr_key) = self.get_addr_key_by_port_fast(&nat_port).await {
127+
if let Some(session) = self.cache.get(&addr_key).await {
128+
return Some(*session);
129+
}
130+
131+
// Reconstruct session from the mapping if it was evicted from cache
132+
// but the eviction listener hasn't removed it from the mapping yet.
133+
return Some(Session {
134+
src_addr: addr_key.src_addr,
135+
dst_addr: addr_key.dst_addr,
136+
src_port: addr_key.src_port,
137+
dst_port: addr_key.dst_port,
138+
nat_port,
139+
});
130140
}
131141

132142
None

0 commit comments

Comments
 (0)