You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
T-Route's netCDF4(python library) dependency can segfault when another netcdf-c<=4.9.1 shared library has already been loaded. You are most likely to run into this issue when running NextGen with routing enabled. This issue is present in netCDF4 versions 1.6.5(latest) and 1.6.4. Versions <=1.6.3 are not affected.
To solve this issue either:
build a netCDF4 wheel from scratch locally: pip uninstall netcdf4; pip install --no-cache-dir --no-binary :all: netcdf4
If you compile and run NextGen with routing enabled with netcdf-c<=4.9.1 and netCDF4==1.6.4 or netCDF4==1.6.5 (python dep), when NextGen starts routing a segmentation fault will occur. This appears to have been resolved in the latest un-released version of netCDF4.
This occurs because of shared library function loading precedence. netCDF41.6.4 and 1.6.5 ship with a pre-compiled version of netcdf-c>4.9.1 as a shared library. netCDF4 calls a shared library function, nc_rc_set, from its included shared library. nc_rc_set calls another library function, NC_rcfile_insert that exists in both the netCDF4 included shared library and whatever netcdf-c shared library you have installed and loaded. When this call is made, it is possible that the NC_rcfile_insert function call, calls the function from your netcdf-c shared library and not the netCDF4 shared library. To make things worse, different versions of netcdf-c have different function signatures for NC_rcfile_insert. This means that nc_rc_set's NC_rcfile_insert call could (in my case it did) have the wrong number of parameters or the order is incorrect. This leads to a segmentation fault when NC_rcfile_insert tries to call the strdup function on one of the function input arguments (that are likely incorrect).
To solve this issue either:
build a netCDF4 wheel from scratch locally: pip uninstall netcdf4; pip install --no-cache-dir --no-binary :all: netcdf4 this is preferred, but takes longer.
With a few small tweaks you can reproduce this issue locally:
# to run this script, first:# linux: `export LD_LIBRARY_PATH=/usr/local/lib/python3.9/site-packages/netCDF4.libs`# mac: `export DYLD_LIBRARY_PATH=/usr/local/lib/python3.9/site-packages/netCDF4.libs`# to find your site-package directory run# `python -c 'import site; print(site.getsitepackages())'importctypesimportcertifiimportosdefstrencode(pystr,encoding=None):
# encode a string into bytes. If already bytes, do nothing.# uses 'utf-8' for default encoding.ifencodingisNone:
encoding='utf-8'returnpystr.encode(encoding)
# you likely need to change this# use `nc-config --libs` to get the path to your `libnetcdf` shared libraryog_nc=ctypes.CDLL("/usr/lib/aarch64-linux-gnu/libnetcdf.so", mode=ctypes.RTLD_GLOBAL)
# this likely will also need to change# run `ls <the-path-to-netCDF4.libs>` and look for `libnetcdf-<xxx>.so.<xx>`nc=ctypes.CDLL("/usr/local/lib/python3.9/site-packages/netCDF4.libs/libnetcdf-15d50133.so.19", mode=ctypes.RTLD_GLOBAL)
# segmentation faultnc.nc_rc_set("HTTP.SSL.CAINFO", strencode(certifi.where()))
TL;DR
T-Route's
netCDF4
(python library) dependency can segfault when anothernetcdf-c<=4.9.1
shared library has already been loaded. You are most likely to run into this issue when running NextGen with routing enabled. This issue is present innetCDF4
versions1.6.5
(latest) and1.6.4
. Versions<=1.6.3
are not affected.To solve this issue either:
netCDF4
wheel from scratch locally:pip uninstall netcdf4; pip install --no-cache-dir --no-binary :all: netcdf4
netCDF4<=1.6.3
.pip install netCDF4==1.6.3
.Current behavior
Note: this has only been confirmed on linux.
If you compile and run
NextGen
with routing enabled withnetcdf-c<=4.9.1
andnetCDF4==1.6.4
ornetCDF4==1.6.5
(python dep), whenNextGen
starts routing a segmentation fault will occur. This appears to have been resolved in the latest un-released version ofnetCDF4
.This occurs because of shared library function loading precedence.
netCDF4
1.6.4
and1.6.5
ship with a pre-compiled version ofnetcdf-c>4.9.1
as a shared library.netCDF4
calls a shared library function,nc_rc_set
, from its included shared library.nc_rc_set
calls another library function,NC_rcfile_insert
that exists in both thenetCDF4
included shared library and whatevernetcdf-c
shared library you have installed and loaded. When this call is made, it is possible that theNC_rcfile_insert
function call, calls the function from yournetcdf-c
shared library and not thenetCDF4
shared library. To make things worse, different versions ofnetcdf-c
have different function signatures forNC_rcfile_insert
. This means thatnc_rc_set
'sNC_rcfile_insert
call could (in my case it did) have the wrong number of parameters or the order is incorrect. This leads to a segmentation fault whenNC_rcfile_insert
tries to call thestrdup
function on one of the function input arguments (that are likely incorrect).To solve this issue either:
netCDF4
wheel from scratch locally:pip uninstall netcdf4; pip install --no-cache-dir --no-binary :all: netcdf4
this is preferred, but takes longer.netCDF4<=1.6.3
.pip install netCDF4==1.6.3
.edit:
small update. if you are a mac user and you use
brew
to manage your packages, this likely will not affect you.brew
'snetcdf
formula ships with4.9.2
.The text was updated successfully, but these errors were encountered: