Add unit test showing some unexpected behaviour of mpsc::channel #1997
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In 'deadpool' I noticed some weird behaviour when calling
Receiver::try_recv
on a channel which is protected by a semaphore in such a way that the size can't exceed its limit: https://github.com/bikeshedder/deadpool/blob/6daa2e7b5bd06d0b516b83f9da1902848e7812e7/src/lib.rs#L266I noticed more objects being returned to the pool than the
max_size
which just didn't make any sense. After some digging I found thattry_recv
sometimes does not returnOk
even if something has already been put into the channel before viatry_send
.This behaviour can be reproduced with the following steps:
try_recv
call.I have no idea how to fix that but please find that test case attached.
As using channel just with
try_send
andtry_lock
is a bit wasteful in my case anyways I just foundcrossbeam_queue
which supports concurrentpush/pop
without any locking.I'm afraid I might have actually introduced that bug myself when adding
Receiver::try_recv
.