Skip to content
Snippets Groups Projects
Commit 33ecd7ab authored by Perry Cheng's avatar Perry Cheng
Browse files

Lift a require so file handle use done early; move a file close from catch to finally

parent 684b3539
No related branches found
No related tags found
No related merge requests found
......@@ -128,9 +128,10 @@ trait ContainerUtils extends Logging {
* It is assumed that the contents does exist and that region is not changing concurrently.
*/
def getDockerLogContent(containerId: String, start: Long, end: Long, mounted: Boolean)(implicit transid: TransactionId): Array[Byte] = {
var fis : java.io.FileInputStream = null
try {
val file = getDockerLogFile(containerId, mounted)
val fis = new java.io.FileInputStream(file)
fis = new java.io.FileInputStream(file)
val channel = fis.getChannel().position(start)
var remain = (end - start).toInt
val buffer = java.nio.ByteBuffer.allocate(remain)
......@@ -140,13 +141,15 @@ trait ContainerUtils extends Logging {
remain = read - read.toInt
Thread.sleep(50) // TODO What is this for?
}
fis.close()
buffer.array
} catch {
case e: Exception =>
error(this, s"getDockerLogContent failed on $containerId")
Array()
} finally {
if (fis != null) fis.close()
}
}
def getContainerHost(container: ContainerName)(implicit transid: TransactionId): ContainerIP = {
......
......@@ -21,6 +21,8 @@
* This file (runner.js) must currently live in root directory for nodeJsAction.
* See issue #102 for a discussion.
*/
var util = require('util');
function NodeActionRunner(message, whisk, console) {
this.userScriptName = getname(message.name);
this.userScriptMain = undefined;
......@@ -39,7 +41,6 @@ function NodeActionRunner(message, whisk, console) {
function closeAndReturn(result) {
var hrEnd = process.hrtime();
var util = require('util');
if (typeof callback.closedConnection == 'undefined') {
callback.closedConnection = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment