There seem to be some "global vars" (unsafePerformIO + NOINLINE) in warps code base. Is it safe to run two instances of warp from the same main function, despite this?
Is it safe to run two warp servers from the same `main`?
157 Views Asked by Georgi Lyubenov At
1
There are 1 best solutions below
Related Questions in HASKELL
- Typeclass projections as inheritance
- How to generate all possible matrices given a number n in Haskell
- Is there a way to get `cabal` to detect changes to non-Haskell source files?
- How to have fixed options using Option.Applicative in haskell?
- How can I create a thread in Haskell that will restart if it gets killed due to any reason?
- Automatic Jacobian matrix in Haskell
- Haskell writing to named pipe unexpectedly fails with `openFile: does not exist (No such device or address)`
- Why does Enum require to implement toEnum and fromEnum, if that's not enough for types larger than Int?
- Non-exhaustive patterns in function compress
- How to get terms names of GADT in Template Haskell?
- Implementing eval() function with Happy parser generator
- How to count the occurences of every element in a list in Haskell fast?
- In Haskell, what does `Con Int` mean?
- Extract a Maybe from a heterogeneous collection
- Haskell, Stack, importing module shows error "Module not found"
Related Questions in YESOD
- How to make a language toggle in Yesod?
- Yesod fails to run on docker
- Upload a file to temporary folder with a Yesod application: encoding issue
- Haskell - Yesod - print route with placeholder
- Configure/disable request logging in yesod
- serve static files in Yesod
- Cross-Compile Yesod app for aarch64 system on x86_64
- Yesod scaffold returns error "The application isn’t built"
- Yesod Esqueleto: could not load module; member of hidden package ‘esqueleto-3.5.8.1’
- How to get inetd and warp to work together
- Haskell Yesod: Sending a Post Request On Image Click
- YesodAuth Google OAuth2 timing out
- How to encode VALUES constant table expression in esqueleto?
- Can't build a simple Yesod project using stack, getting an error with language-javascript-0.7.1.0 package
- Does yesod-bin compile under GHC 9.2.4?
Related Questions in HASKELL-WARP
- Logging Errors and Timeouts in Warp
- How to get inetd and warp to work together
- How to run web server (Warp) in async/concurrent mode?
- Trying to make haskell warp-tls authenticate the client
- Parse dynamic String into HostPreference
- Is it safe to run two warp servers from the same `main`?
- is maxTotalHeaderLength working as expected?
- Warp/WAI Internal Exception Handling
- How to add a specific representation of the request and response of the body of an HTTP request with Haskell Middleware
- Warp / Scotty not terminating thread / resources at end of request
- Anyway to change the default keep-alive close in warp?
- How to Pipe Typed Process to wai-conduit's responseSource?
- throwTo warp tls thread hangs idefinetly
- How to formulate the wai queryString properly?
- WAI tutorial - no instance for (Show Response)
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
It appears to be safe.
At least in
warp-3.3.13, the global variable trick is used (only) to generate keys for thevaultpackage, using code like:Note that this is different than the "usual" global variable trick, since it does not create a global
IORefthat multiple threads might try to use, while each expecting to be the sole user of the reference.Instead, the
vaultpackage provides a type-safe, persistent "store", aVault, that acts like a collection of mutable variables of various types, accessible through unique keys. Keys are generated inIO, effectively usingnewUniquefromData.Unique. TheVaultitself is a pure, safe data structure. It is implemented using unsafe operations, but constructed in a manner that makes it safe. Ultimately, it's aHashMapfromKey a(so, a type-annotatedInteger) to anAnyvalue that can beunsafeCoerced to the needed typea, with type safety guaranteed by the type attached to the key. Values in theVaultare "mutated" by inserting new values in the map, creating an updatedVault, so there's no actual mutation going on here.Since
Vaults are just fancy immutableHashMaps of pure values, there's no danger of two servers overwriting values in each others' vaults, even though they're using the same keys.As far as I can see, all that's needed to ensure safety is that, when a thread calls something like
pauseTimeoutKey, it always gets the same key, and that key is unique among keys for that thread. So, it basically boils down to the thread safety of the global variable trick in general and ofnewUniquewhen used underunsafePerformIO.I've never heard of any cautions against using the global variables trick in multi-threaded code, and
unsafePerformIOis intended to be thread-safe (which is why there's a separate "more efficient but potentially thread-unsafe" versionunsafeDupablePerformIO).newUniqueitself is implemented in a thread-safe manner:and I can't see how running it under
unsafePerformIOwould make it thread-unsafe.