Skip to content

Commit

Permalink
[inferno-vc-server] Use unbounded-delays for threadDelay so it doesn'…
Browse files Browse the repository at this point in the history
…t overflow on armv7l (#133)

We had a `threadDelay` to perform cleanup every hour and the number of
usecs was overflowing on 32 bit arch causing 100% CPU load
  • Loading branch information
albertov authored Sep 23, 2024
1 parent 25e359e commit feb8381
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions inferno-vc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Revision History for inferno-vc
*Note*: we use https://pvp.haskell.org/ (MAJOR.MAJOR.MINOR.PATCH)

## 0.3.7.1 -- 2024-09-23
* Fix overflowing threadDelay on armv7l

## 0.3.7.0 -- 2024-08-19
* Cached client now serializes requests to server for the same script ids in
order to avoid DOSing the server when the same script is requested many times
Expand Down
3 changes: 2 additions & 1 deletion inferno-vc/inferno-vc.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: >=1.10
name: inferno-vc
version: 0.3.7.0
version: 0.3.7.1
synopsis: Version control server for Inferno
description: A version control server for Inferno scripts
category: DSL,Scripting
Expand Down Expand Up @@ -68,6 +68,7 @@ library
, hspec
, QuickCheck
, stm
, unbounded-delays

default-language: Haskell2010
default-extensions:
Expand Down
5 changes: 3 additions & 2 deletions inferno-vc/src/Inferno/VersionControl/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
Expand All @@ -17,8 +18,8 @@ module Inferno.VersionControl.Server
)
where

import Control.Concurrent (threadDelay)
import Control.Concurrent.Async (link, withAsync)
import Control.Concurrent.Thread.Delay (delay)
import Control.Exception (Exception)
import Control.Lens (to, (^.))
import Control.Monad (forM, forever)
Expand Down Expand Up @@ -179,7 +180,7 @@ runServerConfig middleware withEnv runOp serverConfig = do
Right _ -> pure ()
print ("running..." :: String)
-- Cleanup stale autosave scripts in a separate thread every hour:
withLinkedAsync_ (forever $ threadDelay 3600000000 >> cleanup) $
withLinkedAsync_ (forever $ delay 3_600_000_000 >> cleanup) $
-- And run the server:
runSettings (setPort port $ setHost host settingsWithTimeout) $
ungzipRequest $
Expand Down

0 comments on commit feb8381

Please sign in to comment.