You can do a t.interrupt() call, which causes an InterruptException to be thrown from read (which internally calls cancelRead).

Thank you, I’ll try that.

BTW, there should also be a try-catch around the whole task function, which catches this exception, as well as others that may be thrown by connectTCP or read, but currently uncaught exceptions will just terminate the task, so in this case that may be okay.

I see.