为什么每次调用某个模板时ColdFusion都会崩溃/重启?

时间:2015-08-31 14:40:44

标签: coldfusion coldfusion-8

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

这个模板的作用是读取一个充满PDF文件的目录,然后遍历这些文件,为每个使用CFPDF创建几个缩略图。此计划任务已运行多年而没有此问题。在处理单个文件之前,CF服务似乎几乎立即崩溃/重新启动。

我尝试在Staging环境中运行相同的模板,运行正常 - 没有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时,它看起来像是一个内存问题....

以下是我上次尝试运行此模板时文件内容的链接(大到此处包含):

Error Dump File

我仍然非常感谢任何有关如何解决问题的帮助.....

1 个答案:

答案 0 :(得分:4)

查看/ runtime / bin目录,查看是否存在esome错误文件 - 类似于hserrorxxxx.log(不要记得java 1.4的格式)。这是一个热点&#34;错误 - 通常在崩溃时生成。打开一个看看。我的猜测是你要么内存不足,要么你的PDF中嵌入的RGB图像正在服务器上。您可以在hs(hotspot)错误文件中从堆栈中找出它。