diff options
author | bptato <nincsnevem662@gmail.com> | 2024-06-21 20:13:21 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-06-21 20:32:09 +0200 |
commit | 7ffce10055c6b553781e0b747506f6a3a50718a6 (patch) | |
tree | 56f2646592640e6feecd5590289e3c2d811550ad /src/local/client.nim | |
parent | 51ae4cc4ec4402f78bbda6de5207c60b6a1aaf86 (diff) | |
download | chawan-7ffce10055c6b553781e0b747506f6a3a50718a6.tar.gz |
client, pager: fix cached item refcounting bugs
Diffstat (limited to 'src/local/client.nim')
-rw-r--r-- | src/local/client.nim | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/local/client.nim b/src/local/client.nim index ee469652..c52ea71f 100644 --- a/src/local/client.nim +++ b/src/local/client.nim @@ -426,21 +426,25 @@ proc acceptBuffers(client: Client) = pager.alert("Error: failed to set up buffer") continue let key = pager.addLoaderClient(container.process, container.loaderConfig) + let loader = pager.loader stream.withPacketWriter w: w.swrite(key) - let loader = pager.loader if item.fdin != -1: let outputId = item.istreamOutputId if container.cacheId == -1: - (container.cacheId, container.cacheFile) = - loader.addCacheFile(outputId, loader.clientPid) + container.cacheId = loader.addCacheFile(outputId, loader.clientPid) + if container.request.url.scheme == "cache": + # loading from cache; now both the buffer and us hold a new reference + # to the cached item, but it's only shared with the buffer. add a + # pager ref too. + loader.shareCachedItem(container.cacheId, loader.clientPid) var outCacheId = container.cacheId let pid = container.process if item.fdout == item.fdin: loader.shareCachedItem(container.cacheId, pid) loader.resume(item.istreamOutputId) else: - outCacheId = loader.addCacheFile(item.ostreamOutputId, pid).outputId + outCacheId = loader.addCacheFile(item.ostreamOutputId, pid) loader.resume([item.istreamOutputId, item.ostreamOutputId]) w.swrite(outCacheId) if item.fdin != -1: @@ -450,7 +454,11 @@ proc acceptBuffers(client: Client) = discard close(item.fdout) container.setStream(stream, registerFun) else: - # buffer is cloned, no need to cache anything + # buffer is cloned, just share the parent's cached source + loader.shareCachedItem(container.cacheId, container.process) + # also add a reference here; it will be removed when the container is + # deleted + loader.shareCachedItem(container.cacheId, loader.clientPid) container.setCloneStream(stream, registerFun) let fd = int(stream.fd) client.fdmap[fd] = container |