mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-04 22:43:12 +00:00
Avoid raising errors in the spawn threads
This commit is contained in:
parent
1a499a7858
commit
64a4da3549
@ -1,4 +1,3 @@
|
||||
|
||||
{.push raises: [].}
|
||||
|
||||
import std/times
|
||||
|
||||
@ -65,7 +65,7 @@ template callEventCallback(ctx: ptr CodexContext, eventName: string, body: untyp
|
||||
cast[CodexCallback](ctx[].eventCallback)(
|
||||
RET_OK, unsafeAddr event[0], cast[csize_t](len(event)), ctx[].eventUserData
|
||||
)
|
||||
except Exception, CatchableError:
|
||||
except CatchableError:
|
||||
let msg =
|
||||
"Exception " & eventName & " when calling 'eventCallBack': " &
|
||||
getCurrentExceptionMsg()
|
||||
@ -114,12 +114,16 @@ proc sendRequestToCodexThread*(
|
||||
## process proc. See the 'codex_thread_request.nim' module for more details.
|
||||
ok()
|
||||
|
||||
proc runCodex(ctx: ptr CodexContext) {.async.} =
|
||||
proc runCodex(ctx: ptr CodexContext) {.async: (raises: []).} =
|
||||
var codex: CodexServer
|
||||
|
||||
while true:
|
||||
# Wait until a request is available
|
||||
await ctx.reqSignal.wait()
|
||||
try:
|
||||
# Wait until a request is available
|
||||
await ctx.reqSignal.wait()
|
||||
except Exception as e:
|
||||
error "codex thread error while waiting for reqSignal", error = e.msg
|
||||
continue
|
||||
|
||||
# If codex_destroy was called, exit the loop
|
||||
if ctx.running.load == false:
|
||||
|
||||
@ -67,7 +67,7 @@ proc handleRes[T: string | void](
|
||||
|
||||
proc process*(
|
||||
T: type CodexThreadRequest, request: ptr CodexThreadRequest, codex: ptr CodexServer
|
||||
) {.async.} =
|
||||
) {.async: (raises: []).} =
|
||||
## Processes the request in the Codex thread.
|
||||
## Dispatch to the appropriate request handler based on reqType.
|
||||
let retFut =
|
||||
|
||||
@ -87,18 +87,25 @@ proc destroyShared(self: ptr NodeLifecycleRequest) =
|
||||
deallocShared(self[].configJson)
|
||||
deallocShared(self)
|
||||
|
||||
proc createCodex(configJson: cstring): Future[Result[CodexServer, string]] {.async.} =
|
||||
var conf = CodexConf.load(
|
||||
version = codexFullVersion,
|
||||
envVarsPrefix = "codex",
|
||||
cmdLine = @[],
|
||||
secondarySources = proc(
|
||||
config: CodexConf, sources: auto
|
||||
) {.gcsafe, raises: [ConfigurationError].} =
|
||||
if configJson.len > 0:
|
||||
sources.addConfigFileContent(Json, $(configJson))
|
||||
,
|
||||
)
|
||||
proc createCodex(
|
||||
configJson: cstring
|
||||
): Future[Result[CodexServer, string]] {.async: (raises: []).} =
|
||||
var conf: CodexConf
|
||||
|
||||
try:
|
||||
conf = CodexConf.load(
|
||||
version = codexFullVersion,
|
||||
envVarsPrefix = "codex",
|
||||
cmdLine = @[],
|
||||
secondarySources = proc(
|
||||
config: CodexConf, sources: auto
|
||||
) {.gcsafe, raises: [ConfigurationError].} =
|
||||
if configJson.len > 0:
|
||||
sources.addConfigFileContent(Json, $(configJson))
|
||||
,
|
||||
)
|
||||
except ConfigurationError as e:
|
||||
return err("Failed to load configuration: " & e.msg)
|
||||
|
||||
conf.setupLogging()
|
||||
conf.setupMetrics()
|
||||
@ -136,7 +143,7 @@ proc createCodex(configJson: cstring): Future[Result[CodexServer, string]] {.asy
|
||||
|
||||
proc process*(
|
||||
self: ptr NodeLifecycleRequest, codex: ptr CodexServer
|
||||
): Future[Result[string, string]] {.async.} =
|
||||
): Future[Result[string, string]] {.async: (raises: []).} =
|
||||
defer:
|
||||
destroyShared(self)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user