Skip to content

tgsftp_connect() hangs for 50 - 80 seconds on fake address. #46

@Aero-Applications

Description

@Aero-Applications

Thank you for this very useful library.

I was writing a gui application using the library and I noticed that if I enter a non-existent address, cli_loop_main() calls pollwrap_poll_timeout() with a large number like 30,000. I cannot cancel this attempted connection to retry either as pollwrap_poll_timeout() hangs until the specified number of milliseconds have passed.

Investigation has revealed that:

  • the number 30,000 is being extracted from a tree of timers
  • schedule_timer() is only called once during tgsftp_connect() at: backend_init() ->ssh_init() -> random_ref() -> random_create();
  • since no timer is scheduled for quiting the connection attempt, psftp_connect() never regains control to check 'curlibctx->aborted' or 'TGGetTickCount64() > maxtick'
  • since those are never checked, I cannot abort the connection attempt manually, or by setting myContext.connectiontimeoutticks.
  • as a side note: schedule_timer() is called a second time when connecting to an existing address at: cli_main_loop() -> run_toplevel_callbacks() -> run_idempotent_callback() -> ssh_ppl_ic_process_queue_callback() -> ssh_ppl_process_queue() -> ssh2_transport_process_queue() -> ssh2_transport_timer_update();

After placing a few strategic print statements

  • one after: if (curlibctx->aborted) {...} printf("Debug: Loop not aborted.\n");

  • one after: uint64_t maxtick = ...; printf("Debug: Loop progress: %llu/%llu.\n", TGGetTickCount64() - starttick, maxtick - starttick);

  • one after: if (ssh_sftp_loop_iteration() < 0) {} printf("Debug: Loop iteration completed.\n");
    the output looks something like this:

    Debug: Loop not aborted.
    Debug: Loop progress: 0/10000.
    Debug: Loop iteration completed.
    Debug: Loop not aborted.
    Debug: Loop progress: 0/10000.
    Debug: Loop iteration completed.
    Debug: Loop not aborted.
    Debug: Loop progress: 0/10000.
    <Every Application Message for the next 75 seconds>...
    Debug: Loop iteration completed.
    Debug: Loop not aborted.
    Debug: Loop progress: 75001/10000.
    ssh_init: timeout, no connection after 75 seconds
    psftp_connect result is 1

I have not tested my code on windows to see if this behavior persists, and I don't know if this behavior is intentional, and whether or not there is a way to fix it from the applications side (for instance: context.somethingToMakeItNotHangOnFakeAddress = ...)

Thanks for your time, I am really enjoying this library.
:)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions