Skip to content

Remove session-specific directory if module is given Ctrl-C#5739

Merged
PaulWessel merged 28 commits intomasterfrom
terminate-session
Oct 12, 2021
Merged

Remove session-specific directory if module is given Ctrl-C#5739
PaulWessel merged 28 commits intomasterfrom
terminate-session

Conversation

@PaulWessel
Copy link
Member

See #5730 for background. This PR reinstates a check for SIG_INT but the sig_handler has been changed to simply call gmtlib_terminate_session () which will delete the current session directory so that we do not leave useless junk behind. Closes #5730.

We need to test this a bit though. Again, not supported on Windows unless @joa-quim knows how it works there. Run a modern mode command and hit Ctrl-C before it finishes. You should see a message like this

cd ~
rm -f .gmt/server/earth/earth_relief/earth_relief_30s_p/N60E000.earth_relief_30s_p.nc
(base) pwessel@macnut:~-> gmt grdimage @earth_relief_30s -R10/15/60/65 -png t -V
begin [INFORMATION]: Creating a workflow directory /Users/pwessel/.gmt/sessions/gmt_session.1
grdimage [INFORMATION]: Read header from file /Users/pwessel/.gmt/sessions/gmt_session.1/=tiled_97_PX.000000
grdblend [INFORMATION]: Reading Data Table from file /Users/pwessel/.gmt/sessions/gmt_session.1/=tiled_97_PX.000000
grdblend [INFORMATION]: Downloading earth_relief_30s_p/ tile 1 of 1 [N60E000]
grdblend [INFORMATION]: Convert SRTM tile from JPEG2000 to netCDF grid [/Users/pwessel/.gmt/server/earth/earth_relief/earth_relief_30s_p/N60E000.earth_relief_30s_p.nc]
grdconvert [INFORMATION]: File /Users/pwessel/.gmt/server/earth/earth_relief/earth_relief_30s_p/N60E000.earth_relief_30s_p.jp2 reads with GDAL driver JP2OpenJPEG
grdconvert [INFORMATION]: Translating file /Users/pwessel/.gmt/server/earth/earth_relief/earth_relief_30s_p/N60E000.earth_relief_30s_p.jp2 (format gd = Import/export through GDAL) to file /Users/pwessel/.gmt/server/earth/earth_relief/earth_relief_30s_p/N60E000.earth_relief_30s_p.nc (format ns = GMT netCDF format (16-bit integer), CF-1.7)
grdconvert [INFORMATION]: File /Users/pwessel/.gmt/server/earth/earth_relief/earth_relief_30s_p/N60E000.earth_relief_30s_p.jp2 reads with GDAL driver JP2OpenJPEG
grdconvert [INFORMATION]: Reading grid from file /Users/pwessel/.gmt/server/earth/earth_relief/earth_relief_30s_p/N60E000.earth_relief_30s_p.jp2
grdconvert [INFORMATION]: Set boundary condition for all edges: natural
grdconvert [INFORMATION]: Set boundary condition for left   edge: natural
grdconvert [INFORMATION]: Set boundary condition for right  edge: natural
grdconvert [INFORMATION]: Set boundary condition for bottom edge: natural
grdconvert [INFORMATION]: Set boundary condition for top    edge: natural
grdconvert [INFORMATION]: Writing grid to file /Users/pwessel/.gmt/server/earth/earth_relief/earth_relief_30s_p/N60E000.earth_relief_30s_p.nc=ns+s0.5+o0
^Cgrdconvert [NOTICE]: Remove session directory /Users/pwessel/.gmt/sessions/gmt_session.1 before exiting due to Ctrl-C

The session directory should have been removed and you can run the same command (without Ctrl-C) and it will not complain about being in a modern mode session already.

This PR also makes a few changes in gmt.c by now listening for SIG_INT and then doing the above if caught.

Note: If you are running a modern mode script and you hit Ctrl-C then there are complications:

  1. If your script follows the guidelines from gmt --new-script then you have the -e option to bash and the script will quit if there is a failure. Otherwise the script will continue and the next GMT commands will complain about no session.
  2. Your Ctrl->C may also happen to hit a non-GMT command in the script and of course no session dir will be deleted.

We cannot control those things, but we can control interrupting a module.

We could also explain all of this, the way we ensure session continuity etc to preempt dumb things like running gmt begin in one terminal and running the next command in another terminal, or putting a gmt modern mode script in the background (prompt$ my_long_script.sh &) and then run another script in the same terminal. I think that will cause interference.

@PaulWessel PaulWessel added the maintenance Boring but important stuff for the core devs label Sep 8, 2021
@PaulWessel PaulWessel self-assigned this Sep 8, 2021
@anbj
Copy link
Contributor

anbj commented Sep 9, 2021

Doing multiple tests starting a session and ^C-ing, gives a variation of results. It does it's jobs, but in a considerable amount of cases, my terminal just hangs. I have to close/kill it:

$ gmt grdimage @earth_relief_05m -C<(gmt makecpt -Crainbow -T-2000/0/100) -JM15c -RNO -pdf test
^Cgmt [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.784352 before exiting due to Ctrl-C
^C^C^C^C^C^C^C^C^C

I don't know if this is of any help, but just in case;

other outcomes include:

$ gmt grdimage @earth_relief_05m -C<(gmt makecpt -Crainbow -T-2000/0/100) -JM15c -RNO -pdf test
^Cgrdimage [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.781420 before exiting due to Ctrl-C
ERROR: Caught signal number 11 (Segmentation fault) at
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5F__close_cb+0x54)[0x7f444f3e3374]
[0x558]
Stack backtrace:
/usr/local/lib/libgmt.so.6(sig_handler+0x6c)[0x7f4451ca156c]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f4451c3b140]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5F__close_cb+0x54)[0x7f444f3e3374]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x164eeb)[0x7f444f452eeb]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5SL_try_free_safe+0x62)[0x7f444f507c02]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5I_clear_type+0xa1)[0x7f444f4539f1]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5F_term_package+0x2c)[0x7f444f3d67fc]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5_term_library+0x39f)[0x7f444f33874f]
/lib/x86_64-linux-gnu/libc.so.6(+0x3e4d7)[0x7f4451aa04d7]
/lib/x86_64-linux-gnu/libc.so.6(+0x3e67a)[0x7f4451aa067a]
/usr/local/lib/libgmt.so.6(+0x395b1)[0x7f4451ca15b1]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f4451c3b140]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5HF__man_dblock_locate+0x2)[0x7f444f43a542]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x156555)[0x7f444f444555]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5HF__man_op+0x25)[0x7f444f445175]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5HF_op+0x78)[0x7f444f430e48]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x126055)[0x7f444f414055]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5B2__locate_record+0x82)[0x7f444f363352]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5B2_find+0x49a)[0x7f444f35ce9a]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G__dense_lookup+0xbc)[0x7f444f41732c]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G__obj_lookup+0x8f)[0x7f444f428e2f]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x141651)[0x7f444f42f651]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G_traverse+0xf4)[0x7f444f430314]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G_loc_find+0x9d)[0x7f444f421b6d]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5O_open_name+0xba)[0x7f444f48e52a]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5Oopen+0xd0)[0x7f444f468070]
/lib/x86_64-linux-gnu/libnetcdf.so.18(+0x71c47)[0x7f44519a2c47]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x12f96b)[0x7f444f41d96b]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G__link_iterate_table+0x66)[0x7f444f420836]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G__dense_iterate+0x1c4)[0x7f444f4176f4]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G__obj_iterate+0xd4)[0x7f444f427fc4]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G_iterate+0x14f)[0x7f444f41f10f]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x168d68)[0x7f444f456d68]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5Literate+0xc5)[0x7f444f458cc5]
/lib/x86_64-linux-gnu/libnetcdf.so.18(+0x708e9)[0x7f44519a18e9]
/lib/x86_64-linux-gnu/libnetcdf.so.18(NC4_open+0x219)[0x7f44519a4009]
/lib/x86_64-linux-gnu/libnetcdf.so.18(NC_open+0x1de)[0x7f445195c22e]
/lib/x86_64-linux-gnu/libnetcdf.so.18(nc_open+0x14)[0x7f445195c414]
/usr/local/lib/libgmt.so.6(gmt_nc_open+0x20)[0x7f4451d2ee10]
/usr/local/lib/libgmt.so.6(gmt_DCW_operation+0x778)[0x7f4451cfaa28]
/usr/local/lib/libgmt.so.6(gmt_parse_R_option+0x395)[0x7f4451dd3595]
/usr/local/lib/libgmt.so.6(gmt_parse_common_options+0x2304)[0x7f4451de6004]
/usr/local/lib/libgmt.so.6(GMT_Parse_Common+0xbbb)[0x7f4451da758b]
/usr/local/lib/libgmt.so.6(GMT_grdimage+0x28d)[0x7f4451f20cfd]
/usr/local/lib/libgmt.so.6(GMT_Call_Module+0x38e)[0x7f4451cc045e]
gmt(main+0x546)[0x55dae9086716]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xea)[0x7f4451a88d0a]
gmt(_start+0x2a)[0x55dae90874aa]
$ gmt grdimage @earth_relief_05m -C<(gmt makecpt -Crainbow -T-2000/0/100) -JM15c -RNO -pdf test
^Cgmt [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.785551 before exiting due to Ctrl-C
gmt: malloc.c:2379: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
Aborted
$ gmt grdimage @earth_relief_05m -C<(gmt makecpt -Crainbow -T-2000/0/100) -JM15c -RNO -pdf test
^Cgrdimage [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.785551 before exiting due to Ctrl-C
double free or corruption (out)
Aborted
$ gmt grdimage @earth_relief_05m -C<(gmt makecpt -Crainbow -T-2000/0/100) -JM15c -RNO -pdf test
^Cpsconvert [ERROR]: System call [gs -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true '/home/anbj/.gmt/sessions/gmt_session.787978/gmt_0.ps-' 2> '/home/anbj/.gmt/sessions/gmt_session.787978/psconvert_788111c.bb'] returned error 2.
end [ERROR]: Failed to call psconvert
end [ERROR]: gmtinit_process_figures returned error 79
grdimage [ERROR]: Unable to call module end for a one-liner plot.

@PaulWessel
Copy link
Member Author

Please try a few without the process substitution which is a separate process running. Just so we can compare

@PaulWessel
Copy link
Member Author

Basically, gmt has no way of knowing that you kill the makecpt command with Ctrl-C, just that something suddenly got removed in the middle of another module...

@anbj
Copy link
Contributor

anbj commented Sep 9, 2021

Seems to work better with no process substitution.

Still, again, some problems with the terminal not being responsive.

$ gmt grdimage @earth_relief_05m -JM15c -RNO -pdf test
^Cgrdimage [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.791558 before exiting due to Ctrl-C
^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C

And other cases, just to give an impression what the user may see:

$ gmt grdimage @earth_relief_05m -JM15c -RNO -pdf test
^Cgmt [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.791558 before exiting due to Ctrl-C
gmt: malloc.c:2379: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
Aborted

Session was not deleted in this case, so:

$ gmt grdimage @earth_relief_05m -JM15c -RNO -pdf test
gmt [ERROR]: Cannot run a one-liner modern command within an existing modern mode session

Need to clear:

$ gmt clear sessions
$ gmt grdimage @earth_relief_05m -JM15c -RNO -pdf test
^Cgmt [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.797046 before exiting due to Ctrl-C
ERROR: Caught signal number 11 (Segmentation fault) at
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5F__close_cb+0x54)[0x7f719a587374]
[0x558]
Stack backtrace:
/usr/local/lib/libgmt.so.6(sig_handler+0x6c)[0x7f719ce4556c]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f719cddf140]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5F__close_cb+0x54)[0x7f719a587374]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x164eeb)[0x7f719a5f6eeb]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5SL_try_free_safe+0x62)[0x7f719a6abc02]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5I_clear_type+0xa1)[0x7f719a5f79f1]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5F_term_package+0x2c)[0x7f719a57a7fc]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5_term_library+0x39f)[0x7f719a4dc74f]
/lib/x86_64-linux-gnu/libc.so.6(+0x3e4d7)[0x7f719cc444d7]
/lib/x86_64-linux-gnu/libc.so.6(+0x3e67a)[0x7f719cc4467a]
/usr/local/lib/libgmt.so.6(+0x395b1)[0x7f719ce455b1]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f719cddf140]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5_hash_string+0x18)[0x7f719a4de2a8]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5SL_search+0x712)[0x7f719a6a8142]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5P_close+0x281)[0x7f719a66d781]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5I_dec_ref+0x78)[0x7f719a5f8cf8]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5D_close+0x47a)[0x7f719a54de8a]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0xbc4a2)[0x7f719a54e4a2]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5I_dec_ref+0x78)[0x7f719a5f8cf8]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5I_dec_app_ref+0x28)[0x7f719a5f8db8]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5I_dec_app_ref_always_close+0x2a)[0x7f719a5f900a]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5Dclose+0x6c)[0x7f719a52a8fc]
/lib/x86_64-linux-gnu/libnetcdf.so.18(nc4_rec_grp_HDF5_del+0x2b5)[0x7f719cb44f25]
/lib/x86_64-linux-gnu/libnetcdf.so.18(nc4_close_hdf5_file+0x2c)[0x7f719cb419fc]
/lib/x86_64-linux-gnu/libnetcdf.so.18(NC4_close+0x56)[0x7f719cb41c56]
/lib/x86_64-linux-gnu/libnetcdf.so.18(nc_close+0x35)[0x7f719caff885]
/usr/local/lib/libgmt.so.6(gmt_nc_close+0x12)[0x7f719ced2e62]
/usr/local/lib/libgmt.so.6(gmt_DCW_operation+0x121f)[0x7f719ce9f4cf]
/usr/local/lib/libgmt.so.6(gmt_parse_R_option+0x395)[0x7f719cf77595]
/usr/local/lib/libgmt.so.6(gmt_init_module+0x113e)[0x7f719cf7e85e]
/usr/local/lib/libgmt.so.6(GMT_grdimage+0x26a)[0x7f719d0c4cda]
/usr/local/lib/libgmt.so.6(GMT_Call_Module+0x38e)[0x7f719ce6445e]
gmt(main+0x546)[0x55a6ecf8c716]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xea)[0x7f719cc2cd0a]
gmt(_start+0x2a)[0x55a6ecf8d4aa]
$ gmt grdimage @earth_relief_05m -JM15c -RNO -pdf test
^Cpsconvert [ERROR]: System call [gs -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true '/home/anbj/.gmt/sessions/gmt_session.800027/gmt_0.ps-' 2> '/home/anbj/.gmt/sessions/gmt_session.800027/psconvert_800088c.bb'] returned error 2.
end [ERROR]: Failed to call psconvert
end [ERROR]: gmtinit_process_figures returned error 79
grdimage [ERROR]: Unable to call module end for a one-liner plot.

@PaulWessel
Copy link
Member Author

Interesting. Hard to debug these things in the debugger...

@PaulWessel
Copy link
Member Author

Let me know if my changes make any difference.

@PaulWessel
Copy link
Member Author

hi @anbj the latest also calls GMT_Destroy_Session, perhaps that prevents some of the messages you get, but not sure. It seems to report errors after I call exit, which is odd.

@anbj
Copy link
Contributor

anbj commented Sep 9, 2021

(I could not git pull your last commit from the branch. Had to delete the branch and re-fetch it from scratch. Any tips why?)

Still getting a good mix. But I think is works better now.

$ gmt grdimage @earth_relief_10m -JM15c -RNO -pdf test
^Cgrdimage [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.907799 before exiting due to Ctrl-C
double free or corruption (!prev)
Aborted
$ gmt grdimage @earth_relief_10m -JM15c -RNO -pdf test
^Cgrdimage [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.907799 before exiting due to Ctrl-C
gmt: malloc.c:2379: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
Aborted
$ gmt grdimage @earth_relief_10m -JM15c -RNO -pdf test
gmt [ERROR]: Cannot run a one-liner modern command within an existing modern mode session
$ gmt grdimage @earth_relief_10m -JM15c -RNO -pdf test
^Cgrdimage [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.907799 before exiting due to Ctrl-C
ERROR: Caught signal number 11 (Segmentation fault) at
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5F__close_cb+0x54)[0x7f2aadd7b374]
[0x558]
Stack backtrace:
/usr/local/lib/libgmt.so.6(sig_handler+0x6c)[0x7f2ab063956c]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f2ab05d3140]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5F__close_cb+0x54)[0x7f2aadd7b374]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x164eeb)[0x7f2aaddeaeeb]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5SL_try_free_safe+0x62)[0x7f2aade9fc02]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5I_clear_type+0xa1)[0x7f2aaddeb9f1]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5F_term_package+0x2c)[0x7f2aadd6e7fc]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5_term_library+0x39f)[0x7f2aadcd074f]
/lib/x86_64-linux-gnu/libc.so.6(+0x3e4d7)[0x7f2ab04384d7]
/lib/x86_64-linux-gnu/libc.so.6(+0x3e67a)[0x7f2ab043867a]
/usr/local/lib/libgmt.so.6(+0x395b1)[0x7f2ab06395b1]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f2ab05d3140]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5SL_search+0x74a)[0x7f2aade9c17a]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5P_close+0x281)[0x7f2aade61781]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5I_dec_ref+0x78)[0x7f2aaddeccf8]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5D_close+0x48f)[0x7f2aadd41e9f]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0xbc4a2)[0x7f2aadd424a2]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5I_dec_ref+0x78)[0x7f2aaddeccf8]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5I_dec_app_ref+0x28)[0x7f2aaddecdb8]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5I_dec_app_ref_always_close+0x2a)[0x7f2aadded00a]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5Dclose+0x6c)[0x7f2aadd1e8fc]
/lib/x86_64-linux-gnu/libnetcdf.so.18(nc4_rec_grp_HDF5_del+0x1c4)[0x7f2ab0338e34]
/lib/x86_64-linux-gnu/libnetcdf.so.18(nc4_close_hdf5_file+0x2c)[0x7f2ab03359fc]
/lib/x86_64-linux-gnu/libnetcdf.so.18(NC4_close+0x56)[0x7f2ab0335c56]
/lib/x86_64-linux-gnu/libnetcdf.so.18(nc_close+0x35)[0x7f2ab02f3885]
/usr/local/lib/libgmt.so.6(gmt_nc_close+0x12)[0x7f2ab06c6e62]
/usr/local/lib/libgmt.so.6(gmt_DCW_operation+0x121f)[0x7f2ab06934cf]
/usr/local/lib/libgmt.so.6(gmt_parse_R_option+0x395)[0x7f2ab076b5a5]
/usr/local/lib/libgmt.so.6(gmt_parse_common_options+0x2304)[0x7f2ab077e014]
/usr/local/lib/libgmt.so.6(GMT_Parse_Common+0xbbb)[0x7f2ab073f58b]
/usr/local/lib/libgmt.so.6(GMT_grdimage+0x28d)[0x7f2ab08b8d0d]
/usr/local/lib/libgmt.so.6(GMT_Call_Module+0x38e)[0x7f2ab065845e]
gmt(main+0x546)[0x558cb94ac716]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xea)[0x7f2ab0420d0a]
gmt(_start+0x2a)[0x558cb94ad4aa]
$ gmt grdimage @earth_relief_10m -JM15c -RNO -pdf test
^Cgrdimage [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.907799 before exiting due to Ctrl-C
^C^C^C^C^C^C^C^C^C^C^C^C
$ gmt grdimage @earth_relief_10m -JM15c -RNO -pdf test
^Cpsconvert [ERROR]: System call [gs -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true '/home/anbj/.gmt/sessions/gmt_session.908329/gmt_0.ps-' 2> '/home/anbj/.gmt/sessions/gmt_session.908329/psconvert_908369c.bb'] returned error 2.
end [ERROR]: Failed to call psconvert
end [ERROR]: gmtinit_process_figures returned error 79
grdimage [ERROR]: Unable to call module end for a one-liner plot.

@PaulWessel
Copy link
Member Author

I will test this on my Linux laptop today so maybe I can learn some more. Those strange message from malloc sysmalloc is not GMT so I wonder if exit is a macro on your Linux or similar. exit should just exit, not fuss...

@anbj
Copy link
Contributor

anbj commented Sep 9, 2021

Maybe. I'm on Debian 11 Bullseye, if that helps.

And, please don't hesitate to say stop if this is getting too hairy and taking up too much time.

@PaulWessel
Copy link
Member Author

Could @joa-quim perhaps check if this works on WIndows? (Compile, run, CTRL-C the program). We should be able to do Ctrl-C checking on all OS even if the backtrace stuff will be limited to the *nix case. Right now it is all or nothing and Windows is excluded. May even be more important to do this on WIndows since the PID is hardwired to 1.

@PaulWessel
Copy link
Member Author

Hi @anbj - the latest commit works pretty good for me on CentOS. I made some changes that possibly stabilizes things for you as well. let me know.

@anbj
Copy link
Contributor

anbj commented Sep 9, 2021

Yes, works better now.
I rarely get the hanging terminal which in my opinion is the worst.

Some snacks though:

$ gmt grdimage @earth_relief_10m -JM15c -RNO -pdf test
^Cgrdimage [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.1005351 before exiting due to Ctrl-C
HDF5: infinite loop closing library
      P,P,FD,E,SL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL
$ gmt grdimage @earth_relief_10m -JM15c -RNO -pdf test
^Cgrdimage [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.1005351 before exiting due to Ctrl-C
gmt: malloc.c:2379: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
Aborted
$ gmt grdimage @earth_relief_10m -JM15c -RNO -pdf test
gmt [ERROR]: Cannot run a one-liner modern command within an existing modern mode session

(Need to clean this manually now with gmt clear sessions)

$ gmt grdimage @earth_relief_10m -JM15c -RNO -pdf test
^Cpsconvert [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.1005351 before exiting due to Ctrl-C
psconvert [ERROR]: Cannot execute Ghostscript (gs).
psconvert [ERROR]: gmtinit_set_last_dimensions: Could not create file /home/anbj/.gmt/sessions/gmt_session.1005351/gmt.canvas.0 for figure 0
ERROR: Caught signal number 11 (Segmentation fault) at
/lib/x86_64-linux-gnu/libc.so.6(+0x13fba9)[0x7f490ec42ba9]
[0x7f4904e51000]
Stack backtrace:
/usr/local/lib/libgmt.so.6(sig_handler+0x75)[0x7f490ed42585]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f490ecdc140]
/lib/x86_64-linux-gnu/libc.so.6(+0x13fba9)[0x7f490ec42ba9]
/usr/local/lib/libgmt.so.6(gmt_end_module+0x4fa)[0x7f490ee6ec1a]
/usr/local/lib/libgmt.so.6(GMT_psconvert+0x24b9)[0x7f490f061e59]
/usr/local/lib/libgmt.so.6(GMT_Call_Module+0x38e)[0x7f490ed6149e]
/usr/local/lib/libgmt.so.6(gmt_manage_workflow+0xfe5)[0x7f490ee73385]
/usr/local/lib/libgmt.so.6(GMT_end+0x24f)[0x7f490ed4539f]
/usr/local/lib/libgmt.so.6(GMT_Call_Module+0x38e)[0x7f490ed6149e]
/usr/local/lib/libgmt.so.6(gmt_end_module+0x821)[0x7f490ee6ef41]
/usr/local/lib/libgmt.so.6(GMT_grdimage+0x26aa)[0x7f490efc416a]
/usr/local/lib/libgmt.so.6(GMT_Call_Module+0x38e)[0x7f490ed6149e]
gmt(main+0x546)[0x555c9242f716]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xea)[0x7f490eb29d0a]
gmt(_start+0x2a)[0x555c924304aa]
$ gmt grdimage @earth_relief_10m -JM15c -RNO -pdf test
^Cgrdimage [NOTICE]: Remove session directory /home/anbj/.gmt/sessions/gmt_session.1005351 before exiting due to Ctrl-C
ERROR: Caught signal number 11 (Segmentation fault) at
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5F__close_cb+0x54)[0x7f9a35c00374]
[0x558]
Stack backtrace:
/usr/local/lib/libgmt.so.6(sig_handler+0x75)[0x7f9a384be585]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f9a38458140]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5F__close_cb+0x54)[0x7f9a35c00374]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x164eeb)[0x7f9a35c6feeb]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5SL_try_free_safe+0x62)[0x7f9a35d24c02]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5I_clear_type+0xa1)[0x7f9a35c709f1]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5F_term_package+0x2c)[0x7f9a35bf37fc]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5_term_library+0x39f)[0x7f9a35b5574f]
/lib/x86_64-linux-gnu/libc.so.6(+0x3e4d7)[0x7f9a382bd4d7]
/lib/x86_64-linux-gnu/libc.so.6(+0x3e67a)[0x7f9a382bd67a]
/usr/local/lib/libgmt.so.6(sig_handler+0xa9)[0x7f9a384be5b9]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14140)[0x7f9a38458140]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x1a7301)[0x7f9a35cb2301]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5O_msg_copy+0x7d)[0x7f9a35cb435d]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x127d5f)[0x7f9a35c32d5f]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x127870)[0x7f9a35c32870]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5B2__iterate_node+0x175)[0x7f9a35b80575]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5B2__iterate_node+0x1c3)[0x7f9a35b805c3]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5B2__iterate_node+0x55a)[0x7f9a35b8095a]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5B2_iterate+0x6a)[0x7f9a35b799aa]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G__dense_iterate+0x101)[0x7f9a35c34631]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G__dense_build_table+0xcb)[0x7f9a35c34a5b]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G__dense_iterate+0x1a8)[0x7f9a35c346d8]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G__obj_iterate+0xd4)[0x7f9a35c44fc4]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5G_iterate+0x14f)[0x7f9a35c3c10f]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(+0x168d68)[0x7f9a35c73d68]
/lib/x86_64-linux-gnu/libhdf5_serial.so.103(H5Literate+0xc5)[0x7f9a35c75cc5]
/lib/x86_64-linux-gnu/libnetcdf.so.18(+0x708e9)[0x7f9a381be8e9]
/lib/x86_64-linux-gnu/libnetcdf.so.18(NC4_open+0x219)[0x7f9a381c1009]
/lib/x86_64-linux-gnu/libnetcdf.so.18(NC_open+0x1de)[0x7f9a3817922e]
/lib/x86_64-linux-gnu/libnetcdf.so.18(nc_open+0x14)[0x7f9a38179414]
/usr/local/lib/libgmt.so.6(gmt_nc_open+0x20)[0x7f9a3854be50]
/usr/local/lib/libgmt.so.6(gmt_DCW_operation+0x778)[0x7f9a38517a68]
/usr/local/lib/libgmt.so.6(gmt_parse_R_option+0x395)[0x7f9a385f05e5]
/usr/local/lib/libgmt.so.6(gmt_parse_common_options+0x2304)[0x7f9a38603054]
/usr/local/lib/libgmt.so.6(GMT_Parse_Common+0xbbb)[0x7f9a385c45cb]
/usr/local/lib/libgmt.so.6(GMT_grdimage+0x28d)[0x7f9a3873dd4d]
/usr/local/lib/libgmt.so.6(GMT_Call_Module+0x38e)[0x7f9a384dd49e]
gmt(main+0x546)[0x55a1e2d84716]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xea)[0x7f9a382a5d0a]
gmt(_start+0x2a)[0x55a1e2d854aa]
$ gmt grdimage @earth_relief_10m -JM15c -RNO -pdf test
^Cpsconvert [ERROR]: System call [gs -q -dNOPAUSE -dBATCH -dNOSAFER -dPDFSETTINGS=/prepress -dDownsampleColorImages=false -dDownsampleGrayImages=false -dDownsampleMonoImages=false -dUseFlateCompression=true -dEmbedAllFonts=true -dSubsetFonts=true -dMonoImageFilter=/FlateEncode -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dSCANCONVERTERTYPE=2 -dALLOWPSTRANSPARENCY -dMaxBitmap=2147483647 -dUseFastColor=true -sDEVICE=pdfwrite  -g4253x7295 -r720 -sOutputFile='test.pdf' '/home/anbj/.gmt/sessions/gmt_session.1005351/psconvert_1008233d.eps'] returned error 2.
end [ERROR]: Failed to call psconvert
end [ERROR]: gmtinit_process_figures returned error 79
grdimage [ERROR]: Unable to call module end for a one-liner plot.

@joa-quim
Copy link
Member

It does no fix the issue that seems to be that the sig_handler_win32 function does not end up in the gmt.dll

@PaulWessel
Copy link
Member Author

I found an issue in the CMakeLists.txt file: The libgmt list includes gmt_common_sighandler.c twice instead of both c and h. That was probably it all along. Please check again.

@joa-quim
Copy link
Member

Not yet. Still same linking error.

@PaulWessel
Copy link
Member Author

Assuming you fully cleared byte build dir and rebuilt, this makes no sense. Can you think of anything that is different her w.r.t. that function relative to all other GMT exported functions?

@joa-quim
Copy link
Member

Don't know. or some reason the sig_handler_win32 function does not land in the gmt.dll

@PaulWessel
Copy link
Member Author

PaulWessel commented Sep 30, 2021 via email

@joa-quim
Copy link
Member

I can SEE that it's not in the dll and functions are not being skipped. Many attempts to change things gave compiling errors. So it's being compiled. But it just vanishes.

@PaulWessel
Copy link
Member Author

@joa-quim, I have made a few changes to where prototypes are listed etc, perhaps this will help (or not).

@joa-quim
Copy link
Member

joa-quim commented Oct 12, 2021

Yes, now it worked

src\gmt plot -R0/10/0/10 -JX15 -Sc1i -png t
plot [NOTICE]: Remove session directory c:/j/.gmt/sessions/gmt_session.9140 before exiting due to Ctrl-C

But it must take care that gmt_conf.h does not # define NO_SIGHANDLER

@PaulWessel
Copy link
Member Author

But it must take care that gmt_conf.h does not # define NO_SIGHANDLER

Do you mean should this be under #ifndef WIN32?

/* Check whether conditions for sighandler are met */
#if !(defined(HAVE_SIGNAL_H_) && defined(HAVE_SYS_RESOURCE_H_) && \
			defined(HAVE_SYS_TIME_H_) && defined(HAVE_SYS_UCONTEXT_H_))
#	define NO_SIGHANDLER
#endif

@PaulWessel
Copy link
Member Author

I think the answer to my question is yes since those are Unix sys includes. I will add the ifndef.

@joa-quim
Copy link
Member

That is somehow already under an #ifdef _WIN32 but the point is, this #define NO_SIGHANDLER can not be set, otherwise the cleaning will not occur.

@PaulWessel
Copy link
Member Author

OK, so now it cannot be set under WIN32. I will merge this PR once the checks completes.

@PaulWessel PaulWessel merged commit e938302 into master Oct 12, 2021
@PaulWessel PaulWessel deleted the terminate-session branch October 12, 2021 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Boring but important stuff for the core devs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

terminated modern session cause trouble for subsequent session

4 participants