Skip to content

Commit

Permalink
refactor(gateway): cleanup dispatch sequence handling
Browse files Browse the repository at this point in the history
Aligns our code with the spec by removing questionable logic that, even
if hit, was completely wrong. The code tried to resume with the *new*
sequence (instead of the old) and it's not swallowing the, to be,
duplicated event.
  • Loading branch information
vilgotf committed Jun 22, 2023
1 parent c6a5b06 commit fa92610
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions twilight-gateway/src/shard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,27 +1017,8 @@ impl Shard {
_ => {}
}

// READY *should* be the first received dispatch event (which
// initializes `self.session`), but it shouldn't matter that
// much if it's not.
if let Some(session) = self.session.as_mut() {
let last_sequence = session.set_sequence(sequence);

// If a sequence has been skipped then we may have missed a
// message and should cause a reconnect so we can attempt to get
// that message again.
if sequence > last_sequence + 1 {
tracing::info!(
missed_events = sequence - (last_sequence + 1),
"dispatch events have been missed",
);
self.session = self
.close(CloseFrame::RESUME)
.await
.map_err(ProcessError::from_send)?;
}
} else {
tracing::info!("unable to store sequence");
session.set_sequence(sequence);
}
}
Some(OpCode::Heartbeat) => {
Expand Down

0 comments on commit fa92610

Please sign in to comment.