Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,313
    • Issues 4,313
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 385
    • Merge Requests 385
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #19114

Closed
Open
Opened 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
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#19114