diff --git a/Core/WebServer.cpp b/Core/WebServer.cpp index e2b99c5f35..1d9ad232be 100644 --- a/Core/WebServer.cpp +++ b/Core/WebServer.cpp @@ -651,6 +651,16 @@ static MultiPartResult HandleMultipartPart(const http::ServerRequest &request, s } progress.AddBytes(readBytes); bytesTransferred += readBytes; + if (readBytes == 0 && !terminatorFound && (request.In()->AtEnd() || request.In()->HasError())) { + // Peer went away mid-upload (a cancelled browser upload, say). Without this the loop + // spins forever, which also blocks web server shutdown since it joins its threads. + ERROR_LOG(Log::HTTP, "Connection closed during upload of '%s'", filename.c_str()); + if (fp) { + fclose(fp); + File::Delete(destPath); + } + return MultiPartResult::RequestError; + } if (terminatorFound) { INFO_LOG(Log::HTTP, "Found terminator, skipping and proceeding."); break;