Skip to content

Commit

Permalink
Fix the TCP ACK handling in FIN-WAIT-1 state with queued data.
Browse files Browse the repository at this point in the history
whitequark committed Jan 25, 2017
1 parent 53feb67 commit 9aebbff
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/socket/tcp.rs
Original file line number Diff line number Diff line change
@@ -720,10 +720,12 @@ impl<'a> TcpSocket<'a> {
}

// ACK packets in FIN-WAIT-1 state change it to FIN-WAIT-2, if we've already
// sent everything in the transmit buffer.
// sent everything in the transmit buffer, and reset the retransmit timer.
(State::FinWait1, TcpRepr { control: TcpControl::None, .. }) => {
if self.tx_buffer.empty() {
self.set_state(State::FinWait2);
} else {
self.retransmit.reset();
}
}

@@ -2196,4 +2198,45 @@ mod test {
..RECV_TEMPL
}));
}

#[test]
fn test_fin_wait_1_retransmit_reset_after_ack() {
let mut s = socket_established();
s.remote_win_len = 6;
s.send_slice(b"abcdef").unwrap();
s.send_slice(b"123456").unwrap();
s.send_slice(b"ABCDEF").unwrap();
s.close();
recv!(s, time 1000, Ok(TcpRepr {
seq_number: LOCAL_SEQ + 1,
ack_number: Some(REMOTE_SEQ + 1),
payload: &b"abcdef"[..],
..RECV_TEMPL
}));
send!(s, time 1005, TcpRepr {
seq_number: REMOTE_SEQ + 1,
ack_number: Some(LOCAL_SEQ + 1 + 6),
window_len: 6,
..SEND_TEMPL
});
recv!(s, time 1010, Ok(TcpRepr {
seq_number: LOCAL_SEQ + 1 + 6,
ack_number: Some(REMOTE_SEQ + 1),
payload: &b"123456"[..],
..RECV_TEMPL
}));
send!(s, time 1015, TcpRepr {
seq_number: REMOTE_SEQ + 1,
ack_number: Some(LOCAL_SEQ + 1 + 6 + 6),
window_len: 6,
..SEND_TEMPL
});
recv!(s, time 1020, Ok(TcpRepr {
control: TcpControl::Fin,
seq_number: LOCAL_SEQ + 1 + 6 + 6,
ack_number: Some(REMOTE_SEQ + 1),
payload: &b"ABCDEF"[..],
..RECV_TEMPL
}));
}
}

0 comments on commit 9aebbff

Please sign in to comment.