s2-cli icon indicating copy to clipboard operation
s2-cli copied to clipboard

[Detail Bug] Pinger appends task continues after append stream error (missing return)

Open detail-app[bot] opened this issue 10 months ago • 1 comments

Detail Bug Report

https://app.detail.dev/org_89d327b3-b883-4365-b6a3-46b6701342a9/bugs/bug_7c2d20da-f44c-48f9-a3a7-904efffaa8cb

Summary

  • Context: The Pinger struct in src/ping.rs uses two background tasks (appends_handle and reads_handle) to concurrently process append acknowledgments and read records from a stream for latency measurement.
  • Bug: The appends_handle task does not terminate when it encounters an error from the append stream, unlike the reads_handle task which correctly terminates on errors.
  • Actual vs. expected: When append_stream.next() returns an error, the appends task sends the error to the channel but continues running and processing subsequent messages; it should instead terminate immediately after sending the error, matching the behavior of the reads task.
  • Impact: The appends task may continue processing append acknowledgments after an error, potentially causing unexpected messages to appear in subsequent pings, leading to incorrect latency measurements or mismatched append/read pairs.

Code with bug

let appends_handle = tokio::spawn(async move {
    while let Some(next) = append_stream.next().await {
        match next {
            Ok(AppendAck { start, end, .. }) => {
                let append = Instant::now();
                let records = end.seq_num - start.seq_num;
                if records != 1 {
                    appends_tx
                        .send(Err(S2CliError::PingStreamMutated))
                        .expect("appends channel open");
                    return;
                }
                appends_tx.send(Ok(append)).expect("appends channel open");
            }
            Err(e) => {
                appends_tx
                    .send(Err(S2CliError::from(ServiceError::new(
                        ServiceErrorContext::AppendSession,
                        e,
                    ))))
                    .expect("appends channel open");
                // <-- BUG 🔴 Missing return statement - task continues running!
            }
        }
    }
});

Codebase inconsistency

  • reads_handle terminates on error, but appends_handle does not, causing continued polling and potential orphaned messages.

Reference (correct behavior in reads task):

Some(Err(e)) => {
    reads_tx.send(Err(
        ServiceError::new(ServiceErrorContext::ReadSession, e).into()
    )).expect("open reads channel");
    return;  // Correctly terminates the task
}

Current (incorrect behavior in appends task):

Err(e) => {
    appends_tx
        .send(Err(S2CliError::from(ServiceError::new(
            ServiceErrorContext::AppendSession,
            e,
        ))))
        .expect("appends channel open");
    // Missing return statement
}

Recommended fix

Add a return in the error branch of appends_handle to match reads_handle:

Err(e) => {
    appends_tx
        .send(Err(S2CliError::from(ServiceError::new(
            ServiceErrorContext::AppendSession,
            e,
        ))))
        .expect("appends channel open");
    return;  // <-- FIX 🟢 Add this to terminate the task
}

detail-app[bot] avatar Jan 15 '26 22:01 detail-app[bot]

ping replaced with bench cmd

shikhar avatar Jan 25 '26 03:01 shikhar