Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,826
    • Issues 4,826
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 449
    • Merge requests 449
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #20422

Closed
Open
Created Sep 28, 2021 by Mikolaj Konarski@MikolajReporter

Implement System.timeoutWithUnmask as a way to document the deficiency of ordinary System.timeout

The goal is to document the unobvious problem that expressions like timeout 1000 takeMVar, when executed in a loop, lead to data loss. Namely, the IO action (consisting of takeMVar) may be interrupted just after takeMVar finishes and so consumes the value put into the MVar, giving Nothing as the result of the whole timeout expression. That's despite takeMVar being atomic and timeout being subtle and expensive. In the attached program around 15% of the data is lost with timeout 1 and -threaded for me.

This ticket is about implementing System.timeoutWithUnmask (sibling of forkIOwithUnmask), proposed by @duog, that prevents data loss in calls such as timeoutWithUnmask $ \_restore -> takeMVar mv. The documentation would point out the difference and suggest to switch to STM for a more extensible solution using registerDelay (see https://stackoverflow.com/questions/22171895/using-tchan-with-timeout/22182074). As suggested by @duog, the general usage pattern of timeoutWithUnmask would be timeoutWithUnmask $ \restore -> do { r <- restore $ expensive; cheap r; }.

Another angle is to implement tryTakeMVarWithTimeout and cross-reference explaining why flip timeout takeMVar is not equivalent by far.

Here's the file showing the data loss (and an occassional lock-up for an analogous reason): timeoutTest.hs

Edited Sep 28, 2021 by Mikolaj Konarski
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking