Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop when requesting demand in SingleThreadedBufferingSubscriber #6147

Merged
merged 1 commit into from Sep 13, 2021

Conversation

yawkat
Copy link
Member

@yawkat yawkat commented Sep 13, 2021

I found this issue when debugging #6100. It is definitely a bug, but I am not sure yet how important it is to that issue.

Before this patch, requesting data from a SingleThreadedBufferingSubscriber when it is in BUFFERING state would cause an infinite loop.

request first registers the new demand, and then calls flushBuffer to fulfill some of the new demand using currently buffered data. If there was no previous demand, this happens in BUFFERING state. flushBuffer then tries to remove data from the buffer and submit it using onNext, until the buffer is empty or there is no more demand. However, in BUFFERING state, onNext simply readds the data to the buffer and does not touch the demand, so this is an infinite loop.

This fix extracts the "forwarding logic" in onNext to its own method, that does not consider the current state. flushBuffer now uses that method instead of onNext.

@jameskleeh jameskleeh merged commit 1b537c2 into micronaut-projects:3.0.x Sep 13, 2021
@yawkat yawkat deleted the buffer-infinite-loop-0 branch September 14, 2021 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants