one icon indicating copy to clipboard operation
one copied to clipboard

`relent()` not responding to Task cancellation

Open jackgene opened this issue 1 year ago • 2 comments

While implementing Easy Racer scenario 10, I observe that the blocking operation does not stop during a call to relent(), even though the Task should be cancelled (it's also possible the Task isn't cancelled due to https://github.com/propensive/soundness/issues/630).

When running scenario 10, this is observed in the scenario server logs:

scenario=10 Starting blocker for PT9S
scenario=10 Load while blocking: 1.3700397720505704
scenario=10 Load while blocking: 1.264998518100065
scenario=10 Load while blocking: 1.0780863817953164
scenario=10 Load while blocking: 1.1923439332214003
scenario=10 Load while blocking: 1.0769769863439167
scenario=10 Load while blocking: 1.1826739567751585
scenario=10 Load while blocking: 1.075331353094099
scenario=10 Load while blocking: 1.2352128760466203
scenario=10 Mean load while connected to blocker = 1.1844579721783934, Current load = 1.1988273946310775
scenario=10 Mean load while connected to blocker = 1.1844579721783934, Current load = 1.2360186411499214
scenario=10 Mean load while connected to blocker = 1.1844579721783934, Current load = 1.2094920245009237
scenario=10 Mean load while connected to blocker = 1.1844579721783934, Current load = 1.0925878801141071
scenario=10 Mean load while connected to blocker = 1.1844579721783934, Current load = 1.1027617390205022
scenario=10 Mean load while connected to blocker = 1.1844579721783934, Current load = 1.0989857780075007
scenario=10 Mean load while connected to blocker = 1.1844579721783934, Current load = 1.120940559548046
scenario=10 Mean load while connected to blocker = 1.1844579721783934, Current load = 1.107064267556403
scenario=10 Mean load while connected to blocker = 1.1844579721783934, Current load = 1.144906571059734
scenario=10 Mean load while connected to blocker = 1.1844579721783934, Current load = 1.2571903950696703
scenario=10 Mean load while connected to blocker = 1.1844579721783934, Current load = 2.271601802808182
...

(Notice that the Current load remains high even when the server has signaled to the client to stop the CPU-intensive operation (the last scenario=10 Load while blocking: ... line)). The relevant part of the CPU-intensive blocking operation is implemented here.

The alternative implementation) that checks Thread.interrupted() instead of relent() works as expected:

scenario=10 Starting blocker for PT7S
scenario=10 Load while blocking: 1.3329087133111162
scenario=10 Load while blocking: 1.0710594659583226
scenario=10 Load while blocking: 1.2349962194337993
scenario=10 Load while blocking: 1.0070292810701165
scenario=10 Load while blocking: 1.0101974877449766
scenario=10 Load while blocking: 1.2001472486986922
scenario=10 Mean load while connected to blocker = 1.1427230693695039, Current load = 0.9699755765113893
scenario=10 Mean load while connected to blocker = 1.1427230693695039, Current load = 0.008141497707268016

(Notice that the Current load = drops to 0.008... almost as soon as the client receives the signal to stop)

jackgene avatar Dec 28 '24 00:12 jackgene

Thank you! I will check, but I think the fix is quite trivial and relent() does not use the Thread.interrupted flag. I'll find out, and remind myself why I didn't use it originally.

propensive avatar Dec 29 '24 10:12 propensive

Thank you! I will check, but I think the fix is quite trivial and relent() does not use the Thread.interrupted flag. I'll find out, and remind myself why I didn't use it originally.

I figured it might be due to how the soundness.threadModels.platform version is implemented, though I haven't tested EasyRacer with platform threads.

jackgene avatar Dec 29 '24 17:12 jackgene