#812504 swarp: breaks when coadding many overlapping files

Package:
swarp
Source:
swarp
Description:
Resample and co-add together FITS images
Submitter:
Julian Taylor
Date:
2021-01-26 10:27:02 UTC
Severity:
normal
#812504#5
Date:
2016-01-24 13:57:52 UTC
From:
To:
when coadding more than the openfile limit (normally 1024) overlapping
files swarp aborts due to too many open files.
To reproduce create some files with overlapping wcs coordinates, set
ulimit -n to a low enough number and just run SWarp <files>
This was fixed a while ago but apparently in 2.38 the original patch has
been mangled into not working anymore.

1. a in my opinion not useful NOPENFILES_MAX variable was added, and
when you go over the limit it just warns instead of capping the number
of files swarp uses (src/prefs.c:536). The original patch capped the
usage and did not require user configuration or having the process abort
after hours of resampling because the warning was not read.
The fix is simple, set the cap in src/prefs.c, as the actual meat of the
original patch is still in place.
2. the cfitsio based opening leaks open file descriptors somewhere. The
code is kind of convoluted so I could not figure out a good fix. This
half backed attempt works for the visir pipeline but is likely not
appropriate for upstream:
--- a/swarp/src/fits/fitscat.c
+++ b/swarp/src/fits/fitscat.c
@@ -161,6 +161,7 @@ int close_cat(catstruct *cat)
     }

   cat->file = NULL;
+  close_cfitsio(cat);

   return RETURN_OK;
   }
diff --git a/swarp/src/fits/fitstab.c b/swarp/src/fits/fitstab.c
index 5919b2a..95bb2c4 100644
--- a/swarp/src/fits/fitstab.c
+++ b/swarp/src/fits/fitstab.c
@@ -285,6 +285,9 @@ void        copy_tab_fromptr(tabstruct *tabin,
catstruct *catout, int pos)
 /* First, allocate memory and copy data */
    QCALLOC(tabout, tabstruct, 1);
    *tabout = *tabin;
+   /* set fits handle to NULL to avoid double close and hope its not needed
+    * anymore */
+   tabout->infptr = NULL;
    if (tabin->naxis)
      QMEMCPY(tabin->naxisn, tabout->naxisn, int, tabin->naxis);
    if (tabin->headbuf)

#812504#16
Date:
2021-01-26 10:22:31 UTC
From:
To:
Hi Julian,

Looks like it has been several years since this bug report, and noticed this when I took co-maintainer ship of this package couple of days ago.
Apologies for such a long delay.

Does the problem persist with the latest release? If not, could you please forward this patch upstream?

Thanks a lot for you work!