我支持在Windows Server 2003 R2上运行的ColdFusion 8网站(应用了所有Windows安全更新)。该网站平稳运行99.9%的时间。但是,大约2个月前,ColdFusion 8 Application Server服务每晚晚上10:30开始崩溃并重新启动。有一个ColdFusion计划任务每晚晚上10:30运行,因此我尝试手动运行它(直接在浏览器中访问URL),并确信ColdFusion 8 Application Server服务崩溃并重新启动。所以,显然这是导致这种情况发生的一个模板。每次调用某个模板时,为什么ColdFusion会崩溃/重新启动?
这个模板的功能是读取一个充满PDF文件的目录,然后遍历这些文件为每个使用CFPDF创建几个缩略图。此计划任务已运行多年,未出现此问题。在处理单个文件之前,CF服务几乎立即出现崩溃/重新启动。
我试着在我们的Staging环境中运行相同的模板,并且运行正常 - 没有CF重启。我很困惑。
通过ColdFusion日志搜索,没有发现任何东西。
UPDATE:
代码示例:
<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转换时内存问题....
这里是从我最后一次尝试运行此模板(到大,包括在这里),该文件的内容的链接:
我还是非常感谢所有帮助搞清楚如何解决.....
所以开始调试:用调试输出语句加载脚本,找出它崩溃的地方。 –
你在看什么,告诉你ColdFusion正在崩溃并重新启动? –
如果您删除了错误发生后最近2个月添加的所有PDF,有何区别?我们在谈论多少个文件?最大的有多大?你的代码是什么样的? – duncan