Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ and listed with their assets on the

### Fixed

- A lane on a node no longer stops syncing when a file goes while it is
sent (a package manager rewriting `node_modules`): the file is left out
and the next sync sends what is there then.
- A browser or dev server closing a connection through a lane's tunnel is
no longer a warning in the diagnostic log (Windows reports it as
"aborted", 10053).
- Files of a write in progress no longer show among the paths that made a
candidate: atomic writes of editors and agents' tools
(`db.rs.tmp.<pid>.<hex>`), `sed -i`'s `sedXXXXXX`, vim's `4913` and swap
files, Emacs' `.#` and `~` files.
- A dev server's failed rebuild goes to the diagnostic log with its error
lines, not only with its tool's last line: Angular on Windows prints them
after that line, and the log line now waits for them (2 s at most after
the last).

- `--browser` / `DEVSTACK_BROWSER` on Windows: an address with `&` was cut
there by `cmd` (none had one before `/auth?…&next=`).
- The dashboard, opened on a lane before it knew whether the stack runs (a
Expand Down
21 changes: 21 additions & 0 deletions crates/devstack-daemon/src/rebuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ impl Tracker {

/// The last rebuild, as the view shows it at `now`: a finished one for
/// [`SHOWN_MS`], a failed one until the next.
/// Does the rebuild that failed last show only its marker so far, its
/// error lines still to come?
pub fn waits_for_errors(&self) -> bool {
self.marker_only
}

pub fn view(&self, now: u128) -> Option<RebuildView> {
self.current.clone().filter(|c| {
c.state != "ok" || now.saturating_sub(c.since) < SHOWN_MS + c.ms.unwrap_or(0) as u128
Expand Down Expand Up @@ -378,6 +384,21 @@ X [ERROR] TS2729: Property 'flags' is used before its initialization. [plugin an
assert_eq!(v.iter().filter(|r| r.state == "rebuilding").count(), 1);
}

#[test]
fn a_failure_waits_for_its_error_lines() {
// What the diagnostic line waits for (`supervisor::rebuilds`): the
// marker alone, then its first error line.
let mut t = Tracker::new(None).unwrap();
t.feed("> Changes detected. Rebuilding...", 1);
t.feed("Application bundle generation failed. [9.016 seconds]", 2);
assert!(t.waits_for_errors());
t.feed(
"X [ERROR] TS7008: Member 'flags' implicitly has an 'any' type.",
3,
);
assert!(!t.waits_for_errors());
}

#[test]
fn angular_warnings_are_no_failure() {
// A warning (NG8113, a budget) is no error.
Expand Down
39 changes: 35 additions & 4 deletions crates/devstack-daemon/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,10 +1156,16 @@ impl RemoteLane {
.map_err(|e| e.to_string())?;
let mut up = hyper_util::rt::TokioIo::new(up);
let open = crate::telemetry::Tunnel::open(&self.name, &self.node.name);
tokio::io::copy_bidirectional(&mut up, &mut tcp)
.await
.map(|(a, b)| open.closed(a + b))
.map_err(|e| e.to_string())
match tokio::io::copy_bidirectional(&mut up, &mut tcp).await {
Ok((a, b)) => {
open.closed(a + b);
Ok(())
}
// One end hung up without a goodbye (a browser closing a tab or
// a dev server's WebSocket): how connections end, not a fault.
Err(e) if closed_by_a_peer(&e) => Ok(()),
Err(e) => Err(e.to_string()),
}
}

/// Why the node cannot do what `method` on the lane daemon's `path`
Expand Down Expand Up @@ -1282,6 +1288,17 @@ fn release_warning(
Ok((!notes.is_empty()).then(|| notes.join("; ")))
}

/// Did a connection of a tunnel end because one end hung up (reset, aborted,
/// a write to a closed socket)? Windows says "aborted" (10053) where a
/// browser closes a connection it kept alive.
fn closed_by_a_peer(e: &std::io::Error) -> bool {
use std::io::ErrorKind::*;
matches!(
e.kind(),
ConnectionReset | ConnectionAborted | BrokenPipe | UnexpectedEof
)
}

/// A tunnel the node or the lane did not open: what it said, and the
/// releases when they differ (an older lane daemon may serve other ports).
pub fn tunnel_error(what: &str, body: &str, node: &NodeRef) -> String {
Expand Down Expand Up @@ -1341,6 +1358,20 @@ pub fn readiness(view: &serde_json::Value, expected: &[String]) -> Option<Result
mod tests {
use super::{NodeRef, Release, RemoteState, release_warning, tunnel_error, version};

#[test]
fn a_peer_hanging_up_is_how_a_tunnel_ends() {
use std::io::{Error, ErrorKind};
for k in [
ErrorKind::ConnectionReset,
ErrorKind::ConnectionAborted,
ErrorKind::BrokenPipe,
] {
assert!(super::closed_by_a_peer(&Error::from(k)), "{k:?}");
}
assert!(!super::closed_by_a_peer(&Error::from(ErrorKind::TimedOut)));
assert!(!super::closed_by_a_peer(&Error::other("tls")));
}

#[test]
fn a_sync_that_works_does_not_hide_a_port_that_is_not_forwarded() {
let mut st = RemoteState::default();
Expand Down
59 changes: 58 additions & 1 deletion crates/devstack-daemon/src/supervisor/rebuilds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,18 @@ struct Run {
/// The finished rebuild last logged (its start): error lines that follow
/// it update the view, not the log.
logged: Option<u128>,
/// A failed rebuild whose error lines have not come yet (Angular prints
/// them after its marker on Windows): its start, when it last changed and
/// its diagnostic fields, logged [`HOLD`] after its last error line came,
/// or when the next rebuild starts.
held: Option<Held>,
}

type Held = (u128, u128, serde_json::Map<String, serde_json::Value>);

/// How long a failed rebuild's diagnostic line waits for more error lines.
const HOLD: u128 = 2_000;

impl Supervisor {
/// Follow every dev server's log for its rebuilds, as long as this
/// supervisor lives (the main tree's, a lane's).
Expand Down Expand Up @@ -102,6 +112,7 @@ impl Supervisor {
tracker: Tracker::new(svc.rebuild.as_ref()),
live: false,
logged: None,
held: None,
},
);
runs.get_mut(name).expect("inserted")
Expand All @@ -119,11 +130,18 @@ impl Supervisor {
if let Some(v) = tracker.feed(&line, now)
&& was_live
{
if run
.held
.as_ref()
.is_some_and(|(since, _, _)| *since != v.since)
{
self.log_held(name, &mut run.held);
}
let finished = v.state != "rebuilding" && run.logged != Some(v.since);
if finished {
run.logged = Some(v.since);
}
let done = finished.then(|| {
let mut done = finished.then(|| {
let mut extra = serde_json::Map::new();
if let Some(ms) = v.ms {
extra.insert("ms".into(), ms.into());
Expand All @@ -134,9 +152,27 @@ impl Supervisor {
);
extra
});
if tracker.waits_for_errors() {
// Its error lines follow: the log waits for them.
if let Some(extra) = done.take() {
run.held = Some((v.since, now, extra));
}
} else if let Some((since, at, _)) = run.held.as_mut()
&& *since == v.since
{
// One more of its error lines: the next may follow.
*at = now;
}
self.set_rebuild(name, Some(v), done);
}
}
if run
.held
.as_ref()
.is_some_and(|(_, at, _)| now_ms().saturating_sub(*at) >= HOLD)
{
self.log_held(name, &mut run.held);
}
if !was_live {
continue;
}
Expand All @@ -154,6 +190,27 @@ impl Supervisor {
}
}

/// A held failed rebuild to the diagnostic log, as the view has it now
/// (with what error lines came).
fn log_held(&self, name: &str, held: &mut Option<Held>) {
let Some((_, _, extra)) = held.take() else {
return;
};
let rebuild = self
.slots
.lock()
.unwrap()
.get(name)
.and_then(|s| s.view.rebuild.clone());
self.emit_with(
EventBody::DevserverRebuild {
service: name.into(),
rebuild,
},
Some(extra),
);
}

/// The service's rebuild on its view and to the dashboard; `extra` (the
/// time, the result) goes to the diagnostic line of a finished one.
fn set_rebuild(
Expand Down
61 changes: 60 additions & 1 deletion crates/devstack-daemon/src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,42 @@ fn cache(name: &str) -> bool {
)
}

/// Is `name` the file name of a write in progress, renamed onto the real
/// file a moment later? Atomic writes of editors and agents' tools
/// (`db.rs.tmp.33128.2dcc67a056d2`: name, `.tmp.`, process id, random hex),
/// GNU `sed -i` (`sedGr1VFQ`), vim's probe file `4913` and its swap files,
/// Emacs' lock and backup files. The real file's change follows; these
/// would only put names in a candidate's paths that never were the user's.
fn transient(name: &str) -> bool {
let mut parts = name.rsplitn(3, '.');
let write_atomic = matches!(
(parts.next(), parts.next(), parts.next()),
(Some(hex), Some(pid), Some(rest))
if !hex.is_empty() && hex.bytes().all(|b| b.is_ascii_hexdigit())
&& !pid.is_empty() && pid.bytes().all(|b| b.is_ascii_digit())
&& rest.ends_with(".tmp")
);
// Six random letters and digits; a real name of that shape (`sedimentd`)
// is lower case throughout.
let sed = name.len() == 9
&& name.starts_with("sed")
&& name[3..].bytes().all(|b| b.is_ascii_alphanumeric())
&& name[3..]
.bytes()
.any(|b| b.is_ascii_uppercase() || b.is_ascii_digit());
write_atomic
|| sed
|| name == "4913"
|| name.ends_with('~')
|| name.starts_with(".#")
|| (name.starts_with('.') && (name.ends_with(".swp") || name.ends_with(".swx")))
}

/// Is `rel` (repository-relative, `/`-separated) in a directory that never
/// counts: a generated one or a tool's cache?
/// counts (a generated one or a tool's cache), or a write in progress?
pub fn ignored(rel: &str) -> bool {
rel.split('/').any(|n| generated(n) || cache(n))
|| rel.rsplit('/').next().is_some_and(transient)
}

/// Is `rel` in a generated directory (not a cache)? What tells a remote
Expand Down Expand Up @@ -376,6 +408,33 @@ mod tests {
}
}

#[test]
fn writes_in_progress_do_not_count() {
for p in [
"server/src/db.rs.tmp.33128.2dcc67a056d2",
"schema/migrations/0045_icon.sql.tmp.33128.3fd2b0a603be",
"tools/mock/sedGr1VFQ",
"src/4913",
"src/main.rs~",
"src/.#main.rs",
"src/.main.rs.swp",
] {
assert!(super::ignored(p), "{p}");
}
for p in [
"src/db.rs",
"src/data.tmp",
"src/v1.tmp.x.y",
"src/sedan.rs",
"src/seducers",
"bin2/sedimentd",
"docs/4913.md",
"src/swap.swp",
] {
assert!(!super::ignored(p), "{p}");
}
}

#[test]
fn frontend_caches_do_not_count_but_are_synced_to_a_remote_lane() {
for p in [
Expand Down
16 changes: 15 additions & 1 deletion crates/devstack-node/src/nodeclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,14 @@ impl NodeClient {
let read = reader
.await
.map_err(|e| ClientError::Other(e.to_string()))?;
// Gone since it was hashed: like a file that changed, the next sync
// sends what is there then.
if read
.as_ref()
.is_err_and(|e| e.kind() == std::io::ErrorKind::NotFound)
{
return Ok(false);
}
let (status, text) = answer.map_err(|_| {
ClientError::Other(format!(
"{}: not sent within {} min",
Expand Down Expand Up @@ -609,7 +617,13 @@ fn hash_all(
.filter(|k| k.len == meta.len() && Some(k.modified) == modified);
let hash = match cached {
Some(k) => k.hash,
None => hash_file(&path).map_err(|e| ClientError::Io(path.display().to_string(), e))?,
// Gone since it was listed (a package manager rewriting
// `node_modules`): not sent now; the next sync sees what is there.
None => match hash_file(&path) {
Ok(h) => h,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => continue,
Err(e) => return Err(ClientError::Io(path.display().to_string(), e)),
},
};
if let Some(modified) = modified
&& now.duration_since(modified).is_ok_and(|age| age >= SETTLED)
Expand Down