为什么每次调用某个模板时ColdFusion crashing/restarting?

Why is ColdFusion crashing/restarting every time a certain template is called?

我在 Windows Server 2003 R2(应用了所有 Windows 安全更新)上支持 ColdFusion 8 网站 运行ning。该网站在 99.9% 的时间内运行顺畅。然而,大约 2 个月前,ColdFusion 8 应用程序服务器服务开始崩溃,并在每晚 10:30 下午自行重启。有一个 ColdFusion 计划任务,每晚 10:30 下午 运行s,所以我尝试手动 运行ning 它(在浏览器中直接 URL),果然ColdFusion 8 Application Server 服务崩溃并重新启动。所以,显然是这个模板导致了这种情况的发生。

这个模板的作用是读取一个充满 PDF 文件的目录,然后循环遍历这些文件,使用 CFPDF 为每个文件创建几个缩略图。此计划任务已 运行ning 多年未出现此问题。在处理单个文件之前,CF 服务似乎 crashing/restarting 几乎立即。

我尝试 运行在我们的暂存环境中使用相同的模板,它 运行 很好 - 没有重新启动 CF。我很困惑。

搜索了 ColdFusion 日志,但一无所获。

更新:

代码示例:

<cffunction name="createThumbnails" returntype="Void" output="false">
    <cfargument name="sourcePath" type="String" default="" />
    <cfargument name="overwriteExisting" type="Boolean" default="true" />
    <cfargument name="deleteSourceFile" type="Boolean" default="false" />

    <cfset var _image = {} />

    <cfif FileExists(ARGUMENTS.sourcePath)>
        <cfif   ARGUMENTS.overwriteExisting
            OR  NOT FileExists(getXLargeThumbnailPath())>
            <!---   Large Image for MACXpress --->
            <cfset _image =
                REQUEST.UDFLib.Image.scale(
                    imagePath = ARGUMENTS.sourcePath,
                    maxHeight = 777,
                    maxWidth = 627
                    ) />

            <cfimage
                action="write"
                source="#_image#"
                overwrite="true"
                destination="#getXLargeThumbnailPath()#" />
        </cfif>

        <cfif   ARGUMENTS.overwriteExisting
            OR  NOT FileExists(getXLargeThumbnailPath())>
            <cfset _image =
                REQUEST.UDFLib.Image.scale(
                    imagePath = ARGUMENTS.sourcePath,
                    maxHeight = 211,
                    maxWidth = 215
                    ) />

            <cfimage
                action="write"
                source="#_image#"
                overwrite="true"
                destination="#getXLargeThumbnailPath()#" />
        </cfif>

        <cfif   ARGUMENTS.overwriteExisting
            OR  NOT FileExists(getLargeThumbnailPath())>
            <cfset _image =
                REQUEST.UDFLib.Image.scale(
                    imagePath = ARGUMENTS.sourcePath,
                    maxHeight = 265,
                    maxWidth = 215
                    ) />

            <cfimage
                action="write"
                source="#_image#"
                overwrite="true"
                destination="#getLargeThumbnailPath()#" />
        </cfif>

        <cfif   ARGUMENTS.overwriteExisting
            OR  NOT FileExists(getMediumThumbnailPath())>
            <cfset _image =
                REQUEST.UDFLib.Image.scale(
                    imagePath = ARGUMENTS.sourcePath,
                    maxHeight = 100,
                    maxWidth = 100
                    ) />

            <cfimage
                action="write"
                source="#_image#"
                overwrite="true"
                destination="#getMediumThumbnailPath()#" />
        </cfif>

        <cfif   ARGUMENTS.overwriteExisting
            OR  NOT FileExists(getSmallThumbnailPath())>
            <cfset _image =
                REQUEST.UDFLib.Image.scale(
                    imagePath = ARGUMENTS.sourcePath,
                    maxHeight = 50,
                    maxWidth = 50
                    ) />

            <cfimage
                action="write"
                source="#_image#"
                overwrite="true"
                destination="#getSmallThumbnailPath()#" />
        </cfif>

        <cfscript>
            if  (ARGUMENTS.deleteSourceFile) {
                try {
                    FileDelete(ARGUMENTS.sourcePath);
                }
                catch (any e) {
                }
            }
        </cfscript>
    </cfif>
</cffunction>

REQUEST.UDFLib.PDF:

<cffunction
    name="pdfToImageFile"
    returntype="String"
    output="false"
    hint="Converts a phsyical PDF File to a physical Image file and returns the absolute path of the new Image file">
    <cfargument name="sourcePath" type="String" default="" />
    <cfargument name="destinationPath" type="String" default="" />
    <cfargument name="format" type="String" default="png" />

    <cfset var LOCAL = {} />

    <cfif NOT isValidPDF(Trim(ARGUMENTS.sourcePath))>
        <cfthrow
            message="Source file not specified or not a valid PDF file." />
    </cfif>

    <cfif NOT DirectoryExists(Trim(ARGUMENTS.destinationPath))>
        <cfthrow message="Inavlid Destination path." />
    </cfif>

    <cfif
        NOT ListFindNoCase(
                GetWriteableImageFormats(),
                Trim(ARGUMENTS.format)
                )>
        <cfthrow message="Inavlid Image format specified." />
    </cfif>

    <cfscript>
        LOCAL.DestinationFilePath =
                Trim(ARGUMENTS.destinationPath)
            &   "\"
            &   VARIABLES.Library.File.getFileNameWithoutExtension(
                    GetFileFromPath(ARGUMENTS.sourcePath)
                    )
            &   "."
            &   LCase(Trim(ARGUMENTS.format));

        LOCAL.RandomAccessFile =
            CreateObject("java", "java.io.RandomAccessFile")
                .init(
                    CreateObject("java","java.io.File")
                        .init(ARGUMENTS.sourcePath),
                    "r"
                    );

        LOCAL.FileChannel = LOCAL.RandomAccessFile.getChannel();
    </cfscript>

    <cftry>
        <cfset LOCAL.PDFFile =
            CreateObject("java", "com.sun.pdfview.PDFFile")
                .init(
                    LOCAL.FileChannel.map(
                        CreateObject("java", "java.nio.channels.FileChannel$MapMode")
                            .READ_ONLY,
                        0,
                        LOCAL.FileChannel.size()
                        )
                    ) />

        <cfset LOCAL.PDFPage = LOCAL.PDFFile.getPage(1) />

        <cfif NOT StructKeyExists(LOCAL, "PDFPage")>
            <cfthrow message="PDF cannot be converted - unknown error." />
        </cfif>

        <cfcatch type="Any">
            <cfscript>
                LOCAL.RandomAccessFile.close();
            </cfscript>

            <cfthrow message="PDF cannot be converted - unknown error." />
        </cfcatch>
    </cftry>

    <cfscript>
        //  Create new image
        LOCAL.Rectangle = LOCAL.PDFPage.getBBox();

        LOCAL.BufferedImage =
            CreateObject("java", "java.awt.image.BufferedImage")
                .init(
                    LOCAL.Rectangle.width,
                    LOCAL.Rectangle.height,
                    CreateObject("java", "java.awt.image.BufferedImage")
                        .TYPE_INT_RGB
                    );

        LOCAL.Graphics = LOCAL.BufferedImage.createGraphics();

        LOCAL.Graphics.drawImage(
            LOCAL.PDFPage.getImage(
                LOCAL.Rectangle.width,
                LOCAL.Rectangle.height,
                LOCAL.Rectangle,
                JavaCast("null", ""),
                true,
                true
                ),
            0,
            0,
            JavaCast("null", "")
            );

        LOCAL.Graphics.dispose();

        LOCAL.ImageFile =
            CreateObject("java", "java.io.File")
                .init(LOCAL.DestinationFilePath);

        //  Delete existing image file
        if  (LOCAL.ImageFile.exists())
            LOCAL.ImageFile.delete();

        //  Export the image to the specified format
        CreateObject("java", "javax.imageio.ImageIO")
            .write(
                LOCAL.BufferedImage,
                JavaCast("string", Trim(ARGUMENTS.format)),
                LOCAL.ImageFile
                );

        LOCAL.RandomAccessFile.close();

        return LOCAL.DestinationFilePath;
    </cfscript>
</cffunction>

REQUEST.UDFLib.Image:

<cffunction name="scale" returntype="Any" output="false">
    <cfargument name="imagePath" type="String" required="true" />
    <cfargument name="action" type="String" default="fit" hint="shrink, enlarge, or fit"/>
    <cfargument name="minWidth" type="Numeric" default="-1" />
    <cfargument name="minHeight" type="Numeric" default="-1" />
    <cfargument name="maxWidth" type="Numeric" default="-1" />
    <cfargument name="maxHeight" type="Numeric" default="-1" />

    <cfscript>
        var scaledDimensions = {
                width = -1,
                height = -1
            };
        var scaledImage = ImageNew();

        scaledImage = ImageNew(ARGUMENTS.imagePath);

        switch (ARGUMENTS.action) {
            case "shrink":
                scaledDimensions =
                    getDimensionsToShrink(
                        imageHeight = scaledImage.getHeight(),
                        imageWidth = scaledImage.getWidth(),
                        maxWidth = ARGUMENTS.maxWidth,
                        maxHeight = ARGUMENTS.maxHeight
                    );

                break;
            case "enlarge":
                scaledDimensions =
                    getDimensionsToEnlarge(
                        imageHeight = scaledImage.getHeight(),
                        imageWidth = scaledImage.getWidth(),
                        minWidth = ARGUMENTS.minWidth,
                        minHeight = ARGUMENTS.minHeight
                    );

                break;
            default:
                scaledDimensions =
                    getDimensionsToFit(
                        imageHeight = scaledImage.getHeight(),
                        imageWidth = scaledImage.getWidth(),
                        minWidth = ARGUMENTS.minWidth,
                        minHeight = ARGUMENTS.minHeight,
                        maxWidth = ARGUMENTS.maxWidth,
                        maxHeight = ARGUMENTS.maxHeight
                    );

                break;
        }

        if (scaledDimensions.width > 0 && scaledDimensions.height > 0) {
            // This helps the image quality
            ImageSetAntialiasing(scaledImage, "on");

            ImageScaleToFit(
                scaledImage,
                scaledDimensions.width,
                scaledDimensions.height
                );
        }

        return scaledImage;
    </cfscript>
</cffunction>

感谢@MarkAKruger 将我指向 CFROOT\runtime\bin\hs_err_pid*.log 文件。尝试将 PDF 转换为 PNG 时似乎出现了内存问题....

这是我上次尝试 运行 这个模板时的文件内容的 link(太大了,无法包含在此处):

Error Dump File

我仍然非常感谢任何帮助解决问题的方法......

查看 /runtime/bin 目录,看看是否有一些错误文件 - 类似于 hserrorxxxx.log(不记得 java 1.4 的格式)。这是一个 "hotspot" 错误 - 通常在崩溃时生成。打开一个看看。我的猜测是您 运行 内存不足,或者您的 PDF 中嵌入了一个 RGB 图像,导致您的服务器异常终止。您可以从 hs(热点)错误文件中的堆栈中找出它。