Skip to content

Commit

Permalink
Disable faulthandler right before hard exit of the Java VM.
Browse files Browse the repository at this point in the history
Without this, when running the test suite via pyTest on Windows,
we often, or at least occasionally, get `Windows fatal exception:
access violation` errors during the `cleanup()` routine. We already
disable the fault-handler at client start-up, on Windows only,
but pyTest re-enables it as soon as the exit sequence starts. None
of this is really critical, like it doesn't even affect the coverage
report, but it is still a red flag. Disabling the fault-handler
once more right before shutdown seems to get rid of these spurious
crashes entirely. Though that's only true for Windows.

On Linux, this change is definitely not a cure-all. Even with it,
there are still errors. The error message is different, `Fatal Python
error: Segmentation fault`, but similar. It occurs, more specifically,
after `client.disconnect()` was called from `session.cleanup()` in
runs of `test_node.py` and `test_model.py`. It doesn't seem to help to
leave the fault-handler on, like we do at client start-up. It also
doesn't help to turn the fault-handler off right from the start, like
we do on Windows. In fact, the latter makes it worse, to the extent
that Java would then produce fatal error logs dumped to `hs_err_pid*.log`
files.

So whether this is good or bad remains to be seen, and may have to be
re-evaluated by testing at a later date. But at this point, it doesn't
seem to hurt to disable the fault-handler, seeing as how only pyTest
ever meddles with it, and the change is therefore very unlikely to affect
application code in any way, on any platform.
  • Loading branch information
john-hen committed Oct 8, 2021
1 parent 2e7ced1 commit 3a56bb3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mph/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sys # system specifics
import platform # platform information
import threading # multi-threading
import faulthandler # traceback dumps
from logging import getLogger # event logging

########################################
Expand Down Expand Up @@ -158,6 +159,7 @@ def cleanup():
logger.info('Exiting the Java virtual machine.')
sys.stdout.flush()
sys.stderr.flush()
faulthandler.disable()
jpype.java.lang.Runtime.getRuntime().exit(exit_code)
# No code is reached from here on due to the hard exit of the JVM.
logger.info('Java virtual machine has exited.')

0 comments on commit 3a56bb3

Please sign in to comment.