rumqtt icon indicating copy to clipboard operation
rumqtt copied to clipboard

Is waiting on multiple channels with tokio::select! can skip messages or not?

Open sushi-shi opened this issue 2 years ago • 4 comments
trafficstars

By select! documentation it is stated, that it waits for the first future to succeed and drops all other futures. And I wonder whether waiting on multiple receivers with poll in a loop is safe, or I might loose some messages because of it (i.e. whether waiting on a receiver is cancellation safe).

sushi-shi avatar Apr 01 '23 14:04 sushi-shi

Do you mean calling eventloop.poll on multiple branches of select!?

I think it would be easier to answer if you can provide more context on whats your usecase for it.

h3nill avatar Apr 03 '23 07:04 h3nill

@sushi-shi We'll check and get back to you cancellation safety

tekjar avatar Apr 03 '23 08:04 tekjar

Hi, did you come to a conclusion if the future returned by .poll() is cancellation safe? I would use poll() with tokio::select! if it is. Reviewing the code, I think the critical part is in Eventloop::select(). Because this function uses select! internally, I assume that each branch there should be cancel safe, meaning that the whole Eventloop::select() function is cancel safe. Am I right? Would be nice to add this to the documentation of Eventloop::poll()

dlips avatar May 22 '24 18:05 dlips

I would also like to know if .poll() on an EventLoop instance is cancel safe. Thanks!

rtumac avatar Jun 26 '24 22:06 rtumac