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
1 change: 1 addition & 0 deletions docs/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ One file per piece of work, named for it:
| `remote-ops.md` | Commands on many servers, archive and search actions |
| `mosh.md` | Mosh |
| `localization.md` | Translations |
| `bridge-stop-status.md` | AI Bridge: a stopped command's exit status |

Write for the people using the app, in the sections `CHANGELOG.md` uses:
`### Added`, `### Changed`, `### Fixed`, `### Security`. One line per change,
Expand Down
2 changes: 2 additions & 0 deletions docs/changes/bridge-stop-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Fixed
- A command the AI Bridge stopped is now always reported with the stop's own exit status. Before, it was sometimes reported with a different number.
8 changes: 7 additions & 1 deletion lib/services/bridge/bridge_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ class BridgeCommands {
/// when a trapped signal arrives) is repeated while the command's process
/// is still there. A command that died of a signal has been reaped by
/// then, so its status is kept; a zombie `kill -0` still sees is reaped
/// by the next `wait`, so the loop cannot spin. A stopped command's
/// by the next `wait`, so the loop cannot spin. Some shells have already
/// collected the command by the time the cut-short `wait` returns, so
/// `kill -0` finds nothing; one more `wait` then gives the status the
/// shell kept. When the shell kept none (127), the first status stands
/// for a command that ended by itself, and a stop that had begun counts
/// as the stop's TERM. A stopped command's
/// status is the stop's (143 for the TERM, 137 for the KILL).
///
/// The app holds the channel's stdin open for the whole run and closes it
Expand Down Expand Up @@ -117,6 +122,7 @@ exec 3<&-
wait $p
r=$?
while [ "$r" -gt 128 ] && kill -0 $p 2>/dev/null; do wait $p; r=$?; done
if [ "$r" -gt 128 ]; then wait $p 2>/dev/null; q=$?; if [ "$q" -ne 127 ]; then r=$q; elif [ -n "$s" ]; then r=143; fi; fi
if [ -z "$s" ]; then kill -s KILL $w 2>/dev/null; fi
exit $r''';
return 'sh -c ${posixSingleQuote(wrapper)} ssg-bridge '
Expand Down
11 changes: 8 additions & 3 deletions test/bridge_stop_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,18 @@ void main() {
final web = rig.serve(
'web1',
(_) => FakeExecSession(stdout: _probeOutput),
delay: const Duration(milliseconds: 300),
delay: const Duration(seconds: 3),
);
// The channel takes 3 s to open and the call has 100 ms. The bound is
// well clear of both, so a slow runner cannot fail it, while a call
// that waited for the channel still would.
final watch = Stopwatch()..start();
final r = await rig.call('server_stats', {'host': 'web'});
expect(watch.elapsedMilliseconds, lessThan(280));
expect(watch.elapsedMilliseconds, lessThan(2000));
expect(r.isError, true);
await Future<void>.delayed(const Duration(milliseconds: 400));
await Future<void>.delayed(
Duration(milliseconds: 3400 - watch.elapsedMilliseconds),
);
expect(web.sessions.single.stdinClosed, true);
expect(web.sessions.single.wasClosed, true);
});
Expand Down
Loading