on master help sign in
Use safer uuid generation

Prior to 1.3.12, uuid used RandomIO which uses the clock as a seed, so 2 processes started at the same clock time would produce duplicate UUIDs. The solution is to upgrade uuid, and don't use or implement random.

commit5d60172530f6f1ffc92ac8aba01e968d86203dfb authorMichael Xavier <michael@michaelxavier.net> dateWed 8 Jun 2016, 08:25 (10 years ago) parent587fbea
4 files changed+11−10
katip-elasticsearch/katip-elasticsearch.cabal+1−2 katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs+8−8 stack-lts-2.yaml+1 stack.yaml+1
katip-elasticsearch/katip-elasticsearch.cabal+1−2
@@ -29,8 +29,7 @@ library
2929 base >=4.6 && <5
3030 , katip >= 0.2.0.0 && < 0.3
3131 , bloodhound >= 0.11.0.0 && < 0.12
32− , random >= 1.0 && < 1.2
33− , uuid >= 1.3 && < 1.4
32+ , uuid >= 1.3.12 && < 1.4
3433 , aeson >=0.6 && <0.12
3534 , stm >= 2.4.3 && < 2.5
3635 , stm-chans >= 3.0.0.2 && < 3.1
katip-elasticsearch/src/Katip/Scribes/ElasticSearch.hs+8−8
@@ -53,10 +53,10 @@ import Data.Time
5353import Data.Time.Calendar.WeekDate
5454import Data.Typeable
5555import Data.UUID
56+import qualified Data.UUID.V4 as UUID4
5657import Database.Bloodhound
5758import Network.HTTP.Client
5859import Network.HTTP.Types.Status
59−import System.Random
6060-------------------------------------------------------------------------------
6161import Katip.Core
6262import Katip.Scribes.ElasticSearch.Annotations
@@ -64,13 +64,13 @@ import Katip.Scribes.ElasticSearch.Annotations
6464
6565
6666data EsScribeCfg = EsScribeCfg {
67− essRetryPolicy :: RetryPolicy
67+ essRetryPolicy :: RetryPolicy
6868 -- ^ Retry policy when there are errors sending logs to the server
69− , essQueueSize :: EsQueueSize
69+ , essQueueSize :: EsQueueSize
7070 -- ^ Maximum size of the bounded log queue
71− , essPoolSize :: EsPoolSize
71+ , essPoolSize :: EsPoolSize
7272 -- ^ Worker pool size limit for sending data to the
73− , essAnnotateTypes :: Bool
73+ , essAnnotateTypes :: Bool
7474 -- ^ Different payload items coexist in the "data" attribute in
7575 -- ES. It is possible for different payloads to have different
7676 -- types for the same key, e.g. an "id" key that is sometimes a
@@ -83,8 +83,8 @@ data EsScribeCfg = EsScribeCfg {
8383 -- exposes a querying API, we will try to make deserialization and
8484 -- querying transparently remove the type annotations if this is
8585 -- enabled.
86− , essIndexSettings :: IndexSettings
87− , essIndexSharding :: IndexShardingPolicy
86+ , essIndexSettings :: IndexSettings
87+ , essIndexSharding :: IndexShardingPolicy
8888 } deriving (Typeable)
8989
9090
@@ -322,7 +322,7 @@ esDateFormat = "yyyy-MM-dd'T'HH:mm:ssZ||yyyy-MM-dd'T'HH:mm:ss.SSSZ||yyyy-MM-dd'T
322322
323323-------------------------------------------------------------------------------
324324mkDocId :: IO DocId
325−mkDocId = (DocId . T.decodeUtf8 . toASCIIBytes) `fmap` randomIO
325+mkDocId = (DocId . T.decodeUtf8 . toASCIIBytes) `fmap` UUID4.nextRandom
326326
327327
328328-------------------------------------------------------------------------------
stack-lts-2.yaml+1
@@ -13,6 +13,7 @@ extra-deps:
1313 - tasty-0.11.0.2
1414 - tagged-0.8.3
1515 - fail-4.9.0.0
16+ - uuid-1.3.12
1617 # just for 7.8/lts-2
1718 - microlens-th-0.3.0.1
1819 - microlens-0.4.2.0
stack.yaml+1
@@ -13,6 +13,7 @@ extra-deps:
1313 - tasty-0.11.0.2
1414 - tagged-0.8.3
1515 - fail-4.9.0.0
16+ - uuid-1.3.12
1617flags:
1718 katip:
1819 lib-Werror: true