Open aaraney opened 7 months ago
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())'
import ctypes
import certifi
import os
def strencode(pystr,encoding=None):
# encode a string into bytes. If already bytes, do nothing.
# uses 'utf-8' for default encoding.
if encoding is None:
encoding = 'utf-8'
return pystr.encode(encoding)
# you likely need to change this
# use `nc-config --libs` to get the path to your `libnetcdf` shared library
og_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 fault
nc.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
.