diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-02-24 02:59:15 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-02-24 03:07:43 +0100 |
| commit | 2d038b2158ff59dc79f7eb741468fdced1fa4759 (patch) | |
| tree | 8e1c4a0900ee36a16e9452bf5904aaa76063def3 | |
| parent | 6db522c7e5e4a49a91ec3a20a70698e2473889fa (diff) | |
| download | chawan-2d038b2158ff59dc79f7eb741468fdced1fa4759.tar.gz | |
loader: only add output fd to outputMap map in addFd
It is a very bad idea to add it before that, because it could be closed
for various reasons without being removed from the map.
More concretely, this was causing ghost ostream fds to block istream
selects in some cases.
| -rw-r--r-- | src/loader/loader.nim | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim index 39dedf7d..5a3a85bd 100644 --- a/src/loader/loader.nim +++ b/src/loader/loader.nim @@ -190,10 +190,12 @@ proc addFd0(ctx: LoaderContext, handle: LoaderHandle, originalUrl: URL) = handle.cacheUrl = surl proc addFd(ctx: LoaderContext, handle: LoaderHandle, originalUrl: URL) = - handle.output.ostream.setBlocking(false) + let output = handle.output + output.ostream.setBlocking(false) handle.istream.setBlocking(false) ctx.selector.registerHandle(handle.istream.fd, {Read}, 0) ctx.handleMap[handle.istream.fd] = handle + ctx.outputMap[output.ostream.fd] = output ctx.addFd0(handle, originalUrl) proc loadStream(ctx: LoaderContext, handle: LoaderHandle, request: Request, @@ -238,6 +240,7 @@ proc loadStream(ctx: LoaderContext, handle: LoaderHandle, request: Request, if output.registered: output.parent = nil output.istreamAtEnd = true + ctx.outputMap[output.ostream.fd] = output else: output.ostream.close() output.ostream = nil @@ -367,8 +370,6 @@ proc onLoad(ctx: LoaderContext, stream: SocketStream) = request.headers["Referer"] = r if request.proxy == nil or not ctx.config.acceptProxy: request.proxy = ctx.config.proxy - let output = handle.output - ctx.outputMap[output.ostream.fd] = output ctx.loadResource(request, handle) proc acceptConnection(ctx: LoaderContext) = |