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