Free the reqContent when the request was not sent to the thread

This commit is contained in:
Arnaud 2026-06-13 11:49:40 +04:00
parent c630224a59
commit aef4fcc3d4
No known key found for this signature in database
GPG Key ID: A6C7C781817146FA
9 changed files with 29 additions and 8 deletions

View File

@ -95,7 +95,7 @@ proc sendRequestToStorageThread*(
let sentOk = ctx.reqChannel.trySend(req)
if not sentOk:
let reqDesc = $req[]
deallocShared(req)
req.destroy()
return err("Failed to send request to the Logos Storage thread: " & reqDesc)
# trySend has succeeded: req is published in the channel and

View File

@ -41,7 +41,7 @@ proc createShared*(
ret[].logLevel = logLevel.alloc()
return ret
proc destroyShared(self: ptr NodeDebugRequest) =
proc destroyShared*(self: ptr NodeDebugRequest) =
deallocShared(self[].peerId)
deallocShared(self[].logLevel)
deallocShared(self)

View File

@ -72,7 +72,7 @@ proc createShared*(
return ret
proc destroyShared(self: ptr NodeDownloadRequest) =
proc destroyShared*(self: ptr NodeDownloadRequest) =
deallocShared(self[].cid)
deallocShared(self[].filepath)
deallocShared(self)

View File

@ -27,7 +27,7 @@ proc createShared*(T: type NodeInfoRequest, op: NodeInfoMsgType): ptr type T =
ret[].operation = op
return ret
proc destroyShared(self: ptr NodeInfoRequest) =
proc destroyShared*(self: ptr NodeInfoRequest) =
deallocShared(self)
proc getRepo(

View File

@ -90,7 +90,7 @@ proc createShared*(
ret[].configJson = configJson.alloc()
return ret
proc destroyShared(self: ptr NodeLifecycleRequest) =
proc destroyShared*(self: ptr NodeLifecycleRequest) =
deallocShared(self[].configJson)
deallocShared(self)

View File

@ -35,7 +35,7 @@ proc createShared*(
ret[].peerAddresses = peerAddresses
return ret
proc destroyShared(self: ptr NodeP2PRequest) =
proc destroyShared*(self: ptr NodeP2PRequest) =
deallocShared(self[].peerId)
deallocShared(self)

View File

@ -50,7 +50,7 @@ proc createShared*(
return ret
proc destroyShared(self: ptr NodeStorageRequest) =
proc destroyShared*(self: ptr NodeStorageRequest) =
deallocShared(self[].cid)
deallocShared(self)

View File

@ -80,7 +80,7 @@ proc createShared*(
return ret
proc destroyShared(self: ptr NodeUploadRequest) =
proc destroyShared*(self: ptr NodeUploadRequest) =
deallocShared(self[].filepath)
deallocShared(self[].sessionId)
deallocShared(self)

View File

@ -52,6 +52,27 @@ proc createShared*(
ret[].userData = userData
return ret
proc destroy*(request: ptr StorageThreadRequest) =
## Frees the payload (reqContent) and the wrapper on error paths,
## when the request is not handed to the storage thread.
## On success paths, the storage thread frees the payload and the wrapper.
case request[].reqType
of LIFECYCLE:
cast[ptr NodeLifecycleRequest](request[].reqContent).destroyShared()
of INFO:
cast[ptr NodeInfoRequest](request[].reqContent).destroyShared()
of RequestType.DEBUG:
cast[ptr NodeDebugRequest](request[].reqContent).destroyShared()
of P2P:
cast[ptr NodeP2PRequest](request[].reqContent).destroyShared()
of UPLOAD:
cast[ptr NodeUploadRequest](request[].reqContent).destroyShared()
of DOWNLOAD:
cast[ptr NodeDownloadRequest](request[].reqContent).destroyShared()
of STORAGE:
cast[ptr NodeStorageRequest](request[].reqContent).destroyShared()
deallocShared(request)
# NOTE: User callbacks are executed on the working thread.
# They must be fast and non-blocking; otherwise this thread will be blocked
# and no further requests can be processed.