mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-06-27 21:09:28 +00:00
Free the reqContent when the request was not sent to the thread
This commit is contained in:
parent
c630224a59
commit
aef4fcc3d4
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ proc createShared*(
|
||||
|
||||
return ret
|
||||
|
||||
proc destroyShared(self: ptr NodeStorageRequest) =
|
||||
proc destroyShared*(self: ptr NodeStorageRequest) =
|
||||
deallocShared(self[].cid)
|
||||
deallocShared(self)
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user