##// END OF EJS Templates
hgweb: skip logging ConnectionAbortedError...
hgweb: skip logging ConnectionAbortedError Not stacktracing on `ConnectionResetError` was added in 6bbb12cba5a8 (though it was spelled differently for py2 support), but for some reason Windows occasionally triggers a `ConnectionAbortedError` here across various *.t files (notably `test-archive.t` and `test-lfs-serve-access.t`, but there are others). The payload that fails to send seems to be the html that describes the error to the client, so I suspect some code is seeing the error status code and closing the connection before the server gets to write this html. So don't log it, for test stability- nothing we can do anyway. FWIW, the CPython implementation of wsgihander specifically ignores these two errors, plus `BrokenPipeError`, with a comment that "we expect the client to close the connection abruptly from time to time"[1]. The `BrokenPipeError` is swallowed a level up in `do_write()`, and avoids writing the response following this stacktrace. I'm puzzled why a response is being written after these connection errors are detected- the CPython code referenced doesn't, and the connection is now broken at this point. Perhaps these errors should both be handled with the `BrokenPipeError` after the freeze. (The refactoring away from py2 compat may not be desireable in the freeze, but this is much easier to read, and obviously correct given the referenced CPython code.) I suspect this is what 6bceecb28806 was attempting to fix, but it wasn't specific about the sporadic errors it was seeing. [1] https://github.com/python/cpython/blob/b2eaa75b176e07730215d76d8dce4d63fb493391/Lib/wsgiref/handlers.py#L139

File last commit:

r52935:92e23ba2 default
r53050:891f6d56 stable
Show More
progress.rs
92 lines | 3.2 KiB | application/rls-services+xml | RustLexer
//! Progress-bar related things
use std::{
sync::atomic::{AtomicBool, Ordering},
time::Duration,
};
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle};
/// A generic determinate progress bar trait
pub trait Progress: Send + Sync + 'static {
/// Set the current position and optionally the total
fn update(&self, pos: u64, total: Option<u64>);
/// Increment the current position and optionally the total
fn increment(&self, step: u64, total: Option<u64>);
/// Declare that progress is over and the progress bar should be deleted
fn complete(self);
}
const PROGRESS_DELAY: Duration = Duration::from_secs(1);
/// A generic (determinate) progress bar. Stays hidden until [`PROGRESS_DELAY`]
/// to prevent flickering a progress bar for super fast operations.
pub struct HgProgressBar {
progress: ProgressBar,
has_been_shown: AtomicBool,
}
impl HgProgressBar {
// TODO pass config to check progress.disable/assume-tty/delay/etc.
/// Return a new progress bar with `topic` as the prefix.
/// The progress and total are both set to 0, and it is hidden until the
/// next call to `update` given that more than a second has elapsed.
pub fn new(topic: &str) -> Self {
let template =
format!("{} {{wide_bar}} {{pos}}/{{len}} {{eta}} ", topic);
let style = ProgressStyle::with_template(&template).unwrap();
let progress_bar = ProgressBar::new(0).with_style(style);
// Hide the progress bar and only show it if we've elapsed more
// than a second
progress_bar.set_draw_target(ProgressDrawTarget::hidden());
Self {
progress: progress_bar,
has_been_shown: false.into(),
}
}
/// Called whenever the progress changes to determine whether to start
/// showing the progress bar
fn maybe_show(&self) {
if self.progress.is_hidden()
&& self.progress.elapsed() > PROGRESS_DELAY
{
// Catch a race condition whereby we check if it's hidden, then
// set the draw target from another thread, then do it again from
// this thread, which results in multiple progress bar lines being
// left drawn.
let has_been_shown =
self.has_been_shown.fetch_or(true, Ordering::Relaxed);
if !has_been_shown {
// Here we are certain that we're the only thread that has
// set `has_been_shown` and we can change the draw target
self.progress.set_draw_target(ProgressDrawTarget::stderr());
self.progress.tick();
}
}
}
}
impl Progress for HgProgressBar {
fn update(&self, pos: u64, total: Option<u64>) {
self.progress.update(|state| {
state.set_pos(pos);
if let Some(t) = total {
state.set_len(t)
}
});
self.maybe_show();
}
fn increment(&self, step: u64, total: Option<u64>) {
self.progress.inc(step);
if let Some(t) = total {
self.progress.set_length(t)
}
self.maybe_show();
}
fn complete(self) {
self.progress.finish_and_clear();
}
}