Skip to content

Commit de83c2e

Browse files
rsmmrbbannier
authored andcommitted
Fix fiber abortion.
When aborting a fiber, we need to activate it once more, to then leave it for good by raising an `AbortException. Problem was that that exception ended up being caught by user code because it was derived from `std::exception`. This change removes the base class so that the exception is guaranteed to go back to the managing fiber code, where we just ignore it. (cherry picked from commit 193c335)
1 parent 62e033c commit de83c2e

File tree

2 files changed

+13
-5
lines changed
  • hilti/runtime/src
  • tests/Baseline/spicy.types.sink.reassembler.wrong-init-seq

2 files changed

+13
-5
lines changed

hilti/runtime/src/fiber.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,11 @@ detail::Fiber::Fiber(Type type) : _type(type), _fiber(std::make_unique<::Fiber>(
230230
};
231231
}
232232

233-
HILTI_EXCEPTION(AbortException, RuntimeError);
234-
AbortException::~AbortException() = default;
233+
// Exception raised by a fiber resuming operation in case it has been aborted
234+
// in the meantime. This must not be derived from `std::exception` to guarantee
235+
// that it will bubble back up to the fiber code, without being caught by any
236+
// intermediary catch handlers.
237+
struct AbortException {};
235238

236239
detail::Fiber::~Fiber() {
237240
#ifndef NDEBUG
@@ -502,7 +505,7 @@ void detail::Fiber::yield() {
502505
_yield("yield");
503506

504507
if ( _state == State::Aborting )
505-
throw AbortException("processing aborted for input");
508+
throw AbortException();
506509
}
507510

508511
void detail::Fiber::resume() {
@@ -517,7 +520,12 @@ void detail::Fiber::abort() {
517520
if ( ! context::detail::get(true) )
518521
return;
519522

520-
run();
523+
try {
524+
run();
525+
} catch ( const AbortException& ) {
526+
// Exception is expected here when the fiber realizes it has been
527+
// aborted.
528+
}
521529
}
522530

523531
std::unique_ptr<detail::Fiber> detail::Fiber::create() {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
2-
[error] terminating with uncaught exception of type spicy::rt::SinkError: sink cannot update initial sequence number after activity has already been seen (<...>/wrong-init-seq.spicy:20:19-38:1)
2+
[error] terminating with uncaught exception of type spicy::rt::SinkError: sink cannot update initial sequence number after activity has already been seen (<...>/wrong-init-seq.spicy:14:9-14:50)

0 commit comments

Comments
 (0)