deltachat-core-rust icon indicating copy to clipboard operation
deltachat-core-rust copied to clipboard

JSON-RPC python tests frequently fail with OSError: [Errno 9] Bad file descriptor

Open link2xt opened this issue 1 year ago • 1 comments

Failure looks like this:

 ================================== FAILURES ===================================
_______________________________ test_acfactory ________________________________
[gw1] win32 -- Python 3.13.0 D:\a\deltachat-core-rust\deltachat-core-rust\deltachat-rpc-client\.tox\py\Scripts\python.EXE

acfactory = <deltachat_rpc_client.pytestplugin.ACFactory object at 0x000002049AC1DB50>

    def test_acfactory(acfactory) -> None:
        account = acfactory.new_configured_account()
        while True:
            event = account.wait_for_event()
            if event.kind == EventType.CONFIGURE_PROGRESS:
                assert event.progress != 0  # Progress 0 indicates error.
                if event.progress == 1000:  # Success
                    break
            else:
>               print(event)
E               OSError: [Errno 9] Bad file descriptor

tests\test_something.py:60: OSError

This looks like a problem with print usage in pytest when print attempts to print directly and something else (pytest?) closed the file descriptor.

pytest is configured in tox.ini with log_cli = true, maybe this changes something.

Here is CI log (from windows runner): job-logs.txt

This is not the result of teardown, because by the time test_acfactory test failed with this print exception only 50% of tests passed and other tests continue to run successfully.

link2xt avatar Oct 21 '24 10:10 link2xt

This just happened another time with Windows: https://github.com/deltachat/deltachat-core-rust/actions/runs/11440333909/attempts/1

Let's collect some failed runs to find out if it only happens on windows.

link2xt avatar Oct 21 '24 13:10 link2xt

Again Windows: https://github.com/deltachat/deltachat-core-rust/actions/runs/11472543643/job/31925482766

link2xt avatar Oct 23 '24 04:10 link2xt

macOS failure: https://github.com/deltachat/deltachat-core-rust/actions/runs/11489190507/job/31977700193

     def test_two_parallel_realtime_simultaneously(acfactory, path_to_webxdc):
        """Test two peers trying to establish connection simultaneously."""
        ac1, ac2 = acfactory.get_online_accounts(2)
        ac1.set_config("webxdc_realtime_enabled", "1")
        ac2.set_config("webxdc_realtime_enabled", "1")
    
        ac1_webxdc_msg, ac2_webxdc_msg = setup_realtime_webxdc(ac1, ac2, path_to_webxdc)
        ac1_webxdc_msg2, ac2_webxdc_msg2 = setup_realtime_webxdc(ac1, ac2, path_to_webxdc)
    
        setup_thread_send_realtime_data(ac1_webxdc_msg, [10])
        setup_thread_send_realtime_data(ac1_webxdc_msg2, [20])
        setup_thread_send_realtime_data(ac2_webxdc_msg, [30])
        setup_thread_send_realtime_data(ac2_webxdc_msg2, [40])
    
        wait_receive_realtime_data([(ac1_webxdc_msg, [30]), (ac1_webxdc_msg2, [40])])
>       wait_receive_realtime_data([(ac2_webxdc_msg, [10]), (ac2_webxdc_msg2, [20])])

tests/test_iroh_webxdc.py:147: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_iroh_webxdc.py:73: in wait_receive_realtime_data
    log(f"msg {msg.id}: got correct realtime data {data}")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

msg = 'msg 13: got correct realtime data [10]'

    def log(msg):
        print()
>       print("*" * 80 + "\n" + msg + "\n", file=sys.stderr)
E       OSError: [Errno 9] Bad file descriptor

tests/test_iroh_webxdc.py:28: OSError
----------------------------- Captured stdout call -----------------------------

link2xt avatar Oct 24 '24 00:10 link2xt

Another on Windows: https://github.com/deltachat/deltachat-core-rust/actions/runs/11491723293/job/31984758471?pr=6104

link2xt avatar Oct 24 '24 04:10 link2xt

macOS: https://github.com/deltachat/deltachat-core-rust/actions/runs/11526703590/job/32091419565?pr=6113

link2xt avatar Oct 25 '24 23:10 link2xt

So at least it is not limited to Windows. Have not seen any failures on Linux, but if it fails on macOS then likely can fail on Linux as well.

link2xt avatar Oct 25 '24 23:10 link2xt

macOS: https://github.com/deltachat/deltachat-core-rust/actions/runs/11603015899/job/32334090711

Hocuri avatar Oct 31 '24 12:10 Hocuri

Still no idea why stdout file descriptor becomes "bad" before the test finishes, but made a PR to remove all print() calls: https://github.com/deltachat/deltachat-core-rust/pull/6185

link2xt avatar Nov 07 '24 00:11 link2xt