changeset 257:d6d48c7cc141

fix: issue with shared heap memory in settings
author Sam <sam@basx.dev>
date Wed, 24 May 2023 23:00:21 +0700
parents 15ebddcb4fb8
children 9cbd9780ff65
files src/semicongine/settings.nim
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/semicongine/settings.nim	Wed May 24 22:59:55 2023 +0700
+++ b/src/semicongine/settings.nim	Wed May 24 23:00:21 2023 +0700
@@ -1,4 +1,5 @@
 import std/logging
+import std/streams
 import std/parsecfg
 import std/strutils
 import std/sequtils
@@ -11,7 +12,7 @@
 
 when CONFIGHOTRELOAD:
   var
-    configUpdates: Channel[(string, Config)]
+    configUpdates: Channel[(string, string)]
     notifyConfigUpdate: Channel[bool]
   configUpdates.open()
   notifyConfigUpdate.open()
@@ -49,7 +50,7 @@
   when CONFIGHOTRELOAD:
     while configUpdates.peek() > 0:
       let (updatedNamespace, updatedConfig) = configUpdates.recv()
-      allsettings[updatedNamespace] = updatedConfig
+      allsettings[updatedNamespace] = loadConfig(newStringStream(updatedConfig))
   if not allsettings.hasKey(namespace):
     raise newException(Exception, &"Namespace {namespace} not found, available namespaces are {allsettings.keys().toSeq}")
   allsettings[namespace].getSectionValue(section, key)
@@ -95,7 +96,8 @@
           configModTimes[namespace] = Time()
         let lastMod = namespace.getFile().getLastModificationTime()
         if lastMod != configModTimes[namespace]:
-          configUpdates.send((namespace, namespace.getFile().loadConfig()))
+          let configStr = newFileStream(namespace.getFile()).readAll()
+          configUpdates.send((namespace, configStr))
           notifyConfigUpdate.send(true)
       sleep CONFIGHOTRELOADINTERVAL
   var thethread: Thread[void]