atomicDEX-API
atomicDEX-API copied to clipboard
Call to my_swap_status rpc or implementation function occasionally may fail
Bug description Test test_taker_completes_swap_after_taker_payment_spent_while_offline may fail with error:
thread 'docker_tests::swap_watcher_tests::test_taker_completes_swap_after_taker_payment_spent_while_offline' panicked at 'called `Result::unwrap()` on an `Err` value: "!status of 35844273-888e-42dc-9652-5a35f67ff20a: {\"error\":\"rpc:215] dispatcher_legacy:141] lp_swap:1117] saved_swap:211] fs:192] Error deserializing a swap: EOF while parsing a value at line 1 column 0\"}"', /home/runner/work/komodo-defi-framework/komodo-defi-framework/mm2src/mm2_test_helpers/src/for_tests.rs:2269:53
Commit: 9a82349f14aa0acbd083f2787c1599ed7c80cbf6 Environment: Native (non-wasm)
More Information Apparently this may happen for swaps v1 due to concurrent access to the swap file: writing swap state to the swap file (while a swap in progress) and reading from the swap file by querying my_swap_status(). Example of this is test_taker_completes_swap_after_taker_payment_spent_while_offline test which waits for swap completion periodically calling my_swap_status().
Proposed Solution We have several options to fix this:
- use existing in the code solution with .tmp file when swap state is initially written to a tmp file and then renamed to its actual name. This prevents concurrent reading and writing the swap file (easiest one).
- use RwLock to guard access to the swap file
- migrate swap file to a field in the db for the native environment.