Skip to content

Capture and save state of the thread when suspending #369

Closed

Description

@harendra-kumar

When composing multiple streams using concurrent combinators like async, ahead or parallel we stop a thread midway in the stream if we find that the buffer is full. When we resume the stream later we start using a fresh monadic state from the SVar (svarMrun), at this point we have lost the state of the stream as it was when the stream stopped and we are now using incorrect state.

To resolve this we can either block the thread instead of stopping it or we can capture the state of the stream and store it along with the stream in the workqueue.

Activity

  1. added
    type:bug
    on Jan 15, 2020
  2. harendra-kumar commented on Jan 15, 2020

    @harendra-kumar
    MemberAuthor

    For example, in workLoopLIFO:

        yieldk a r = do
            res <- liftIO $ sendYield sv winfo (ChildYield a)
            if res
            then foldStreamShared st yieldk single run r
            else liftIO $ do
                enqueueLIFO sv q r
                sendStop sv winfo
    

    The sendStop case loses the state of the monad and we start using fresh state later.

  3. adithyaov commented on Jul 4, 2020

    @adithyaov
    Member

    The easiest idea is to captureMonadState and save RunInIO while enqueuing, with the stream itself. We might not need to save RunInIO in the SVar if this is followed, as every stream in the work queue will be associated with a RunInIO. There is probably a better solution, need to think about it.

  4. added this to the 0.8.0 milestone on Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type:bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions