From 2d038b2158ff59dc79f7eb741468fdced1fa4759 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 24 Feb 2024 02:59:15 +0100 Subject: 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. --- src/loader/loader.nim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/loader') 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) = -- cgit