Skip to content

Commit fe0ff03

Browse files
committed
Put the state updates after close, like before
1 parent d799470 commit fe0ff03

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

crates/client-api/src/routes/subscribe.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,11 +1048,6 @@ async fn ws_send_loop_inner<T, U, Encoder>(
10481048
match msg {
10491049
UnorderedWsMessage::Close(close_frame) => {
10501050
log::trace!("intiating close");
1051-
state.close();
1052-
// We won't be polling `messages` anymore,
1053-
// so let senders know.
1054-
messages.close();
1055-
10561051
// Send outstanding frames until one that has the FIN
10571052
// bit set. Ensures the client won't receive partial
10581053
// messages before we shut down.
@@ -1074,6 +1069,20 @@ async fn ws_send_loop_inner<T, U, Encoder>(
10741069
log::warn!("error sending close frame: {e:#}");
10751070
break;
10761071
}
1072+
1073+
// Lastly, update the state.
1074+
//
1075+
// NOTE: It's ok to not update the state if we fail to
1076+
// send the close frame, because we assume that the main
1077+
// loop with exit when this future terminates.
1078+
// We shouldn't set the state to closed before sending
1079+
// the close frame, however, as we would start dropping
1080+
// messages immediately (defeating the purpose of the
1081+
// close handshake).
1082+
state.close();
1083+
// We won't be polling `messages` anymore,
1084+
// so let senders know.
1085+
messages.close();
10771086
},
10781087
UnorderedWsMessage::Ping(bytes) => {
10791088
log::trace!("sending ping");

0 commit comments

Comments
 (0)