From 87f9bd656b2a8a8d4ebd029ba6a78f1dc93558eb Mon Sep 17 00:00:00 2001 From: bptato Date: Tue, 9 May 2023 12:34:58 +0200 Subject: Improve debugging, reduce crashes Loader no longer dies when not everything is read from the stream. --- src/io/loader.nim | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/io/loader.nim') diff --git a/src/io/loader.nim b/src/io/loader.nim index 2cb2b295..15b8e3e2 100644 --- a/src/io/loader.nim +++ b/src/io/loader.nim @@ -94,6 +94,7 @@ proc onLoad(ctx: LoaderContext, stream: Stream) = if not ctx.config.filter.match(request.url): stream.swrite(-1) # error stream.flush() + stream.close() else: for k, v in ctx.config.defaultHeaders.table: if k notin request.headers.table: @@ -131,8 +132,11 @@ proc acceptConnection(ctx: LoaderContext) = proc finishCurlTransfer(ctx: LoaderContext, handleData: HandleData, res: int) = if res != int(CURLE_OK): - handleData.ostream.swrite(int(res)) - handleData.ostream.flush() + try: + handleData.ostream.swrite(int(res)) + handleData.ostream.flush() + except IOError: # Broken pipe + discard discard curl_multi_remove_handle(ctx.curlm, handleData.curl) handleData.ostream.close() handleData.cleanup() @@ -234,7 +238,11 @@ proc fetch*(loader: FileLoader, input: Request): Promise[Response] = let fd = int(stream.source.getFd()) loader.registerFun(fd) let promise = Promise[Response]() - loader.connecting[fd] = ConnectData(promise: promise, request: input) + loader.connecting[fd] = ConnectData( + promise: promise, + request: input, + stream: stream + ) proc newResponse(res: int, request: Request, stream: Stream = nil): Response = return Response( -- cgit 1.4.1-2-gfad0