Commit f7be6801 authored by Rob Swindell's avatar Rob Swindell 💬

Fix race condition in add_outbound_files() causing "Unable to open FLO file".

The directory list is catpured *before* the lock file is "taken", so it can
happen that another process (e.g. instance of binkit) has dealt with one or
more of the files by the time we take the lock and attempt to open the file.

Also, updated error log messages a bit.
parent 2849731e
Pipeline #332 passed with stage
in 19 minutes and 31 seconds
...@@ -136,7 +136,7 @@ function lock_flow(file) ...@@ -136,7 +136,7 @@ function lock_flow(file)
} }
if (!f.open("wb")) { if (!f.open("wb")) {
f.date = orig_date; f.date = orig_date;
log(LOG_WARNING, "Error " + f.error + " opening " + f.name); log(LOG_WARNING, "Error " + f.error + " opening lock file: " + f.name);
return false; return false;
} }
f.date = now; f.date = now;
...@@ -146,7 +146,7 @@ function lock_flow(file) ...@@ -146,7 +146,7 @@ function lock_flow(file)
if(!mkpath(ret.bsy.name.slice(0, -file_getname(ret.bsy.name).length))) if(!mkpath(ret.bsy.name.slice(0, -file_getname(ret.bsy.name).length)))
log(LOG_WARNING, "MKPATH ERROR " + errno + " (" + errno_str + "): " + ret.bsy.name); log(LOG_WARNING, "MKPATH ERROR " + errno + " (" + errno_str + "): " + ret.bsy.name);
if (!ret.bsy.open("wb")) { // Used to include 'e' mode flag (which never worked) if (!ret.bsy.open("wb")) { // Used to include 'e' mode flag (which never worked)
log(LOG_WARNING, "Error " + ret.bsy.error + " creating " + ret.bsy.name); log(LOG_WARNING, "Error " + ret.bsy.error + " creating lock file: " + ret.bsy.name);
if (!take_lockfile(ret.bsy)) { if (!take_lockfile(ret.bsy)) {
log(LOG_NOTICE, "Lock on "+ret.bsy.name+" failed."); log(LOG_NOTICE, "Lock on "+ret.bsy.name+" failed.");
return undefined; return undefined;
...@@ -219,7 +219,7 @@ function add_outbound_files(addrs, bp) ...@@ -219,7 +219,7 @@ function add_outbound_files(addrs, bp)
var fnchars = '0123456789abcdefghijklmnopqrstuvwxyz'; var fnchars = '0123456789abcdefghijklmnopqrstuvwxyz';
var fname; var fname;
if(file_isdir(file)) if(file_isdir(file) || !file_exists(file))
return; return;
var ext = file_getext(file); var ext = file_getext(file);
if (ext !== undefined) if (ext !== undefined)
...@@ -233,7 +233,7 @@ function add_outbound_files(addrs, bp) ...@@ -233,7 +233,7 @@ function add_outbound_files(addrs, bp)
case '.ilo': case '.ilo':
flo = new File(file); flo = new File(file);
if (!flo.open("r")) { if (!flo.open("r")) {
log(LOG_ERROR, "Unable to open FLO file '"+flo.name+"': " + flo.error); log(LOG_ERROR, "Error " + flo.error + " opening FLO file: " + flo.name);
break; break;
} }
if (bp.cb_data.binkit_flow_contents[flo.name] === undefined) if (bp.cb_data.binkit_flow_contents[flo.name] === undefined)
...@@ -337,7 +337,7 @@ function remove_file(fname) ...@@ -337,7 +337,7 @@ function remove_file(fname)
if (file_remove(fname)) if (file_remove(fname))
log(LOG_INFO, "Deleted file: " + fname); log(LOG_INFO, "Deleted file: " + fname);
else else
log(LOG_ERROR, "Unable to delete file: " + fname); log(LOG_ERROR, "Error " + errno + " (" + errno_str + ") deleting file: " + fname);
} }
...@@ -406,12 +406,12 @@ function rename_or_move(src, dst_dir, dst_fname) ...@@ -406,12 +406,12 @@ function rename_or_move(src, dst_dir, dst_fname)
return true; return true;
sf = new File(src); sf = new File(src);
if (!sf.open("rb")) { if (!sf.open("rb")) {
log(LOG_ERR, "Error " + sf.error + " opening " + sf.name); log(LOG_ERR, "Error " + sf.error + " opening source file for move: " + sf.name);
return false; return false;
} }
df = new File(dst); df = new File(dst);
if (!df.open("wb")) { // Used to include 'e' mode flag (which never worked) if (!df.open("wb")) { // Used to include 'e' mode flag (which never worked)
log(LOG_ERR, "Error " + df.error + " opening " + df.name); log(LOG_ERR, "Error " + df.error + " opening destination file for move: " + df.name);
sf.close(); sf.close();
return false; return false;
} }
...@@ -554,7 +554,7 @@ function callout_done(bp) ...@@ -554,7 +554,7 @@ function callout_done(bp)
// We have some unsent files in here... re-write the flo file... // We have some unsent files in here... re-write the flo file...
f = new File(key); f = new File(key);
if (!f.open("r+")) { if (!f.open("r+")) {
log(LOG_ERROR, "Unable to update flow file '"+key+"': " + f.error); log(LOG_ERROR, "Error " + f.error + " opening flow file for update: " + key);
return; return;
} }
lines = f.readAll(2048); lines = f.readAll(2048);
...@@ -679,7 +679,7 @@ function check_held(addr, scfg, myaddr) ...@@ -679,7 +679,7 @@ function check_held(addr, scfg, myaddr)
if (!f.exists) if (!f.exists)
return false; return false;
if (!f.open("r")) { if (!f.open("r")) {
log(LOG_ERROR, "Unable to open hold file '"+f.name+"': " + f.error); log(LOG_ERROR, "Error " + f.error + " opening hold file: " + f.name);
return true; return true;
} }
until = f.readln(); until = f.readln();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment