Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7773755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:12:28+00:00 2026-06-01T17:12:28+00:00

My program reads a line from a network socket and writes it to disc.

  • 0

My program reads a line from a network socket and writes it to disc. Since lines can be really long and strings had terrible performance I started using lazy byte strings. Now it seems that Haskell will go past hClose on disc file handle without actually flushing whole byte string to disc, so doing:

  • open file for writing
  • write byte string to file with hPut
  • close file
  • open file for reading

usually results in openFile: resource busy (file is locked).

Is it possible to enforce evaluation and wait for the whole byte string to be written before closing the file, so I can be sure that the file is actually closed after that operation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:12:29+00:00Added an answer on June 1, 2026 at 5:12 pm

    Since the only other answer is of the “use something else” variety I’m posting my own solution. Using this function after hClose will hang the thread until lazy write is done.

    waitForLazyIO location = do
        t <- liftIO $ try $ openFile location AppendMode
        handle t
        where
            handle (Right v) = hClose v
            handle (Left e)
                -- Add some sleep if you expect the write operation to be slow.
                | isAlreadyInUseError e = waitForLazyIO location
                | otherwise = throwError $ show e
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that reads data from a file line-by-line. I would like
I have a binary program developed for Linux which reads lines from a server's
I'm looking at this program that reads input lines and then sorts them, from
My Ruby program reads lines from stdin and uses puts to print to stdout
Write a simple program that reads a line from the keyboard and outputs the
I have a spring batch program which reads from a file and writes to
I have a program that reads from a txt file line by line splits
I have a program which runs an external, command line utility and reads the
This program reads emails (really just a .txt file structured like an email) and
My SSIS program reads as input from a .csv file. The file has about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.