Skip to content
GitLab
Projects Groups Snippets
  • /
  • 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 5,401
    • Issues 5,401
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 591
    • Merge requests 591
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #19114
Closed
Open
Issue created Dec 23, 2020 by Philipp@zander

`readFile` leaks file descriptors in the presence of asynchronous exceptions

Summary

System.IO.readFile leaks file descriptors in the presence of asynchronous exceptions.

Steps to reproduce

Run

module Main where

import Control.Concurrent
import Data.Foldable
import System.IO

main :: IO ()
main =
  do
    for_ [1..300] go
    -- at this point, execute `ls -l "/proc/$(pidof readfile-test-exe)/fd"`
    -- every listing of `test.txt` constitutes a leaked file descriptor
    getLine
    pure ()

go :: Integer -> IO ()
go n =
  do
    id <- forkIO (readFile "test.txt" >>= putStr)
    threadDelay 1
    killThread id
    pure ()

(https://gitlab.com/rdnz/readfile-test/-/blob/system-io/app/Main.hs).

Execute ls -l "/proc/$(pidof readfile-test-exe)/fd" in a new terminal.

Expected behavior

ls -l "/proc/$(pidof readfile-test-exe)/fd" should not list any test.txt.

Environment

  • GHC version used: 8.8.4
  • Operating System: NixOS 20.03.2843.14006b724f3
  • Kernel Version: 5.4.60
  • OS Type: 64-bit
  • Processors: 2 × Intel® Core™2 Duo CPU P8700 @ 2.53GHz
  • Memory: 3.6 GiB of RAM
Edited Dec 23, 2020 by Philipp
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking