Closed J08nY closed 3 years ago
Looks like we're not threadsafe
Can you provide a minimal failing example?
The following code crashes on fpylll 0.5.2dev with fplll 5.3.3. It reaches the BKZ reduction line and then when the alarm fires it SIGSEGVs or similar.
#!/usr/bin/env python3
from threading import Thread
from cysignals.alarm import alarm, AlarmInterrupt
from fpylll import LLL, BKZ, IntegerMatrix
class Test(Thread):
def __init__(self, matrix):
super().__init__()
self.matrix = matrix
def run(self):
try:
print("start")
alarm(10)
print("BKZ")
reduced = BKZ.reduction(self.matrix, BKZ.Param(block_size=40, strategies=BKZ.DEFAULT_STRATEGY, auto_abort=True))
print("BKZ done")
except AlarmInterrupt:
print("Alarm")
pass
if __name__ == "__main__":
A = IntegerMatrix(120, 120)
A.randomize("ntrulike", bits=64)
t = Test(A)
t.start()
t.join()
Output:
start
BKZ
------------------------------------------------------------------------
/usr/lib/python3.8/site-packages/cysignals/signals.cpython-38-x86_64-linux-gnu.so(+0x7dad)[0x7fd13b50ddad]
/usr/lib/python3.8/site-packages/cysignals/signals.cpython-38-x86_64-linux-gnu.so(+0x7e6c)[0x7fd13b50de6c]
/usr/lib/python3.8/site-packages/cysignals/signals.cpython-38-x86_64-linux-gnu.so(+0xa670)[0x7fd13b510670]
/usr/lib/libc.so.6(+0x3d6a0)[0x7fd13be806a0]
/usr/lib/libfplll.so.6(_ZN5fplll6MatGSOINS_4Z_NRIA1_12__mpz_structEENS_5FP_NRIdEEE13row_addmul_siEiil+0x2d)[0x7fd13a34818d]
/usr/lib/libfplll.so.6(_ZN5fplll12LLLReductionINS_4Z_NRIA1_12__mpz_structEENS_5FP_NRIdEEE5babaiEiii+0x2ed)[0x7fd13a25aa7d]
[0x7fcf49d442b0]
------------------------------------------------------------------------
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "./example.py", line 18, in run
reduced = BKZ.reduction(self.matrix, BKZ.Param(block_size=40, strategies=BKZ.DEFAULT_STRATEGY, auto_abort=True))
SystemError: <cyfunction bkz_reduction at 0x7fcf49f01c70> returned NULL without setting an error
Thanks! This means interrupting the programme while running and then expecting everything to be fine won't work. That is, I was wrong above: this is not a question of thread safety but cold interrupting a computation and expecting a sane state after.
I see two options:
multiprocessing
i.e. forking
I am using the
threading
module to run multiple threads of BKZ and CVP solving (on different matrix objects) and thecysignals
alarm
to set a timeout on the threads to only run BKZ for a given time, I am getting the following error when the timeout is hit: