warmcat / libwebsockets

canonical libwebsockets.org networking library

Home Page:https://libwebsockets.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The callback LWS_CALLBACK_CLIENT_CONNECTION_ERROR has experienced a delay.

sush126 opened this issue · comments

Hi @lws-team,

I am using the minimal-ws-client application from the lws minimal example with lws version 4.3.2. When I send a connection request to the server, and the server is not up in my case, it takes almost ~20 seconds to detect that the server is not reachable. I receive the event LWS_CALLBACK_CLIENT_CONNECTION_ERROR after ~20 seconds. Is there anything we can do to get an earlier detection of the connection failure? I have attached the logs for your reference.

Note: This delayed LWS_CALLBACK_CLIENT_CONNECTION_ERROR event is not reproducible on the Linux platform. I have observed this issue only on the Windows platform.

lws with Windows logs:
libweb-issue

lws with linux platform:
linux-lws-issue

It looks like linux tells us in 3s that it's not going to happen, but windows takes longer. I don't plan to spend any time on that, but patches are welcome. You will want to look around lib/core-net/client/connect3.c.

You can also try main branch.

Thanks @lws-team .
I have checked with the main branch, but I am experiencing the same issue. I have attached the logs. From the logs, there is one line that says:
lws_plat_set_socket_options_ip: priority and ip sockets options not implemented on windows platform
lws_plat_set_socket_options_ip: set use exclusive addresses
is there anything which i miss while building for windows ?
main-lws

Windows does not support these things, it's not going to be to do with what you're seeing.

If the underlying OS acts different, lws will act different. If you want to change it you will have to shift your mind from just using lws and asking for help to studying what happens during these interactions with the OS, google for the windows behaviours etc, and providing patches to change the behaviours.

Thanks @lws-team .
In the connect3.c file for Windows, there is polling using lws_sul_schedule for a default duration of 15 seconds. Additionally, there is a scheduled callback to poll and check its status every 1000 microseconds, which can lead to a delay of 15 seconds. You can configure this polling time using the following variable using lws_create_context api.

wsi->a.context->timeout_secs: Default is 15 seconds.
wsi->a.context->win32_connect_check_interval_usec: Default is 1000 microseconds.

The win32_connect_check_interval_usec parameter is currently only available in the main branch. Do you have any plans to backmerge this into v4.3.2? Or should I raise a Merge Request (MR) for the same?

attached screenshot for the same.
lws_code

@lws-team
I have created a patch to improve the connect call logic on Windows for libwebsockets version 4.3.2.This changes are already available on main branch .
refactor-connect-logic-for-windows.patch
Please find the patch attached. Kindly review and consider integrating it into the v4.3.2 branch.

Thanks, but I'm afraid because this needs abi changes, it can't go on a stable release. v4.3.2 is a tag anyway, not a branch, it points to a static tree that can't change.

Your options are use main, or a specific version of main by specifying the hash of it, or to externally patch v4.3-stable branch yourself.