sent_messages: Lift event loop restarting to transmit.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-06 10:13:05 -07:00 committed by Tim Abbott
parent 339b1351f8
commit 0c991d813f
3 changed files with 31 additions and 33 deletions

View File

@ -1,7 +1,6 @@
import * as Sentry from "@sentry/browser";
import * as blueslip from "./blueslip";
import * as server_events from "./server_events";
export let next_local_id;
export const messages = new Map();
@ -49,30 +48,9 @@ export class MessageState {
this.rendered_changed = true;
}
maybe_restart_event_loop() {
if (this.saw_event) {
// We got our event, no need to do anything
return;
}
blueslip.log(
`Restarting get_events due to delayed receipt of sent message ${this.local_id}`,
);
server_events.restart_get_events();
}
report_server_ack() {
this.server_acked = true;
this.maybe_finish_txn();
// We only start our timer for events coming in here,
// since it's plausible the server rejected our message,
// or took a while to process it, but there is nothing
// wrong with our event loop.
if (!this.saw_event) {
setTimeout(() => this.maybe_restart_event_loop(), 5000);
}
}
report_event_received() {
@ -137,15 +115,6 @@ export function start_send(local_id) {
return state.start_send();
}
export function report_server_ack(local_id) {
const state = get_message_state(local_id);
if (!state) {
return;
}
state.report_server_ack();
}
export function mark_disparity(local_id) {
const state = get_message_state(local_id);
if (!state) {

View File

@ -7,6 +7,7 @@ import * as people from "./people";
import * as reload from "./reload";
import * as reload_state from "./reload_state";
import * as sent_messages from "./sent_messages";
import * as server_events from "./server_events";
import * as stream_data from "./stream_data";
export function send_message(request, on_success, error) {
@ -28,7 +29,32 @@ export function send_message(request, on_success, error) {
// box and turning off spinners and reifying locally echoed messages.
on_success(data);
// Once everything is done, get ready to report times to the server.
sent_messages.report_server_ack(request.local_id);
const state = sent_messages.get_message_state(request.local_id);
/* istanbul ignore if */
if (!state) {
return;
}
state.report_server_ack();
// We only start our timer for events coming in here,
// since it's plausible the server rejected our message,
// or took a while to process it, but there is nothing
// wrong with our event loop.
/* istanbul ignore if */
if (!state.saw_event) {
setTimeout(() => {
if (state.saw_event) {
// We got our event, no need to do anything
return;
}
blueslip.log(
`Restarting get_events due to delayed receipt of sent message ${request.local_id}`,
);
server_events.restart_get_events();
}, 5000);
}
},
error(xhr, error_type) {
if (error_type !== "timeout" && reload_state.is_pending()) {

View File

@ -14,7 +14,10 @@ const reload = mock_esm("../src/reload");
const reload_state = mock_esm("../src/reload_state");
const sent_messages = mock_esm("../src/sent_messages", {
start_tracking_message: noop,
report_server_ack: noop,
get_message_state: () => ({
report_server_ack: noop,
saw_event: true,
}),
start_send: noop,
});