Jakub Kicinski <[email protected]> writes:

> On Wed, 19 Nov 2025 14:40:41 +0100 Petr Machata wrote:
>> > @@ -163,7 +162,7 @@ KSFT_DISRUPTIVE = True
>> >          entry = global_defer_queue.pop()
>> >          try:
>> >              entry.exec_only()
>> > -        except:
>> > +        except Exception:  
>> 
>> This used to catch KsftTerminate, which we use for SIGTERM handling, now
>> it doesn't anymore. I think it could legitimately appear in that context
>> if SIGTERM si delivered while exec_only() is running.
>> 
>> IMHO it should catch BaseException, like ksft_run() already does.
>
> TBH I haven't thought of this. Are you thinking that we shouldn't
> interrupt the execution of deferred cleanups when SIGTERM arrives?
> Fair point, but I think we'd need more code to handle that properly 🤔️
> Right now we ignore SIGTERM which isn't great. After this patch we'll
> no longer ignore it and have the whole test exit. Neither actually
> catches the exception and sets stop=True in ksft_run()..

Well, previously at least the rest of the defer queue would be run, now
it's skipped. Which -- OK, likely if you SIGTERM in the middle of a
cleanup, chances are the cleanup is stuck and the sigterm then skips it,
which is what you want.

It's a pick your poison. Ignore C-c or ignore deferred cleanups :)

Given this is supposed to be a cleanup patch, it would make sense to
just s/bare except/except BaseException/ and leave the behavior broken.
The commit message indicates it's a NOP make-linter-happy patch, but
then it's not really.

> WDYT about leaving this patch as is and doing this on top:

It's a good stop-gap.

> diff --git a/tools/testing/selftests/net/lib/py/ksft.py 
> b/tools/testing/selftests/net/lib/py/ksft.py
> index 83b1574f7719..5a667ad22ef4 100644
> --- a/tools/testing/selftests/net/lib/py/ksft.py
> +++ b/tools/testing/selftests/net/lib/py/ksft.py
> @@ -268,7 +268,12 @@ KSFT_DISRUPTIVE = True
>              KSFT_RESULT = False
>              cnt_key = 'fail'
>  
> -        ksft_flush_defer()
> +        try:
> +            ksft_flush_defer()
> +        except BaseException as e:
> +            stop |= isinstance(e, KeyboardInterrupt)
> +            # Flush was interrupted, try to finish the job best we can
> +            ksft_flush_defer()
>  
>          if not cnt_key:
>              cnt_key = 'pass' if KSFT_RESULT else 'fail'


Reply via email to