libwebsockets icon indicating copy to clipboard operation
libwebsockets copied to clipboard

When client created with invalid server IP ... goes in constant looping for 17-20 seconds

Open Paramveer24b opened this issue 3 years ago • 4 comments

Description:- In windows I created a client, and gave invalid IP to connect as a server. There is a function in libwebsocket

 lws_plat_service_tsi()
{
  // In below loop if value of n is positive then this loops continues .
     for (i = 0; i < pt->fds_count; ++i) {
  	pfd = &pt->fds[i];
  	if (!(pfd->events & LWS_POLLOUT))
  		continue;

	wsi = wsi_from_fd(context, pfd->fd);
	if (!wsi || wsi->listener)
		continue;
	if (wsi->sock_send_blocking)
		continue;
	pfd->revents = LWS_POLLOUT;
	n = lws_service_fd(context, pfd);
	if (n < 0 )
		return -1;

	/*
	 * Force WSAWaitForMultipleEvents() to check events
	 * and then return immediately.
	 */
	timeout_us = 0;

	/* if something closed, retry this slot */
	if (n)
		i--;
	printf("looping\n");
}

}

In my case n > 0 thats why loop gets continued ...but this situation remains for 17-20 seconds every time. In result for loop continues in constant looping for this much time.

But this is not the case on Linux with same client with invalid server IP address.

there is a check to break this loop as below (different code for UNIX and Windows in libwebsocket)

/* any socket with events to service? */
	for (n = 0; n < (int)pt->fds_count; n++) {
	lws_sockfd_type fd = pt->fds[n].fd;

	if (!pt->fds[n].revents)
		continue;

	m = lws_service_fd_tsi(context, &pt->fds[n], tsi);
	if (m < 0) {
		lwsl_err("%s: lws_service_fd_tsi returned %d\n",
			 __func__, m);
		return -1;
	}

	/* if something closed, retry this slot since may have been
	 * swapped with end fd */
	if (m && pt->fds[n].fd != fd)
		n--;
}

If I apply pt->fds[n].fd != fd this condition in windows then above issue resolved.

Is this correct solution for above issue or I have to do something else.

And if this is correct ...will you be able to provide a patch for this ?

Paramveer24b avatar Jul 20 '22 05:07 Paramveer24b

I encountered the same problem, and it depends on whether it is just a wrong address or whether there is a port blocking

Log with normal behavior 10.10.10.1
[2022/08/30 16:05:41:8569] U: LWS minimal ws client
[2022/08/30 16:05:41:8569] N: LWS: 4.3.0-unknown, NET CLI SRV H1 H2 WS ConMon IPv6-absent
[2022/08/30 16:05:41:8579] N:  ++ [wsi|0|pipe] (1)
[2022/08/30 16:05:41:8843] N:  ++ [vh|0|default||-1] (1)
[2022/08/30 16:05:41:8921] N: lws_plat_vhost_tls_client_ctx_init: Imported 51 certs from plat store
[2022/08/30 16:05:41:8921] D: [vh|0|default||-1]: lws_protocol_init_vhost: not instantiating lws-minimal-client
[2022/08/30 16:05:41:8930] D: _realloc: size 1200: __lws_wsi_create_with_role
[2022/08/30 16:05:41:8930] D: : lws_role_transition: wsistate 0x200, ops (unset)
[2022/08/30 16:05:41:8930] D: : lws_vhost_bind_wsi: vh default: wsi none/none, count_bound_wsi 1
[2022/08/30 16:05:41:8930] D: _realloc: size 368: client ws struct
[2022/08/30 16:05:41:8930] D: : lws_role_transition: wsistate 0x10000200, ops h1
[2022/08/30 16:05:41:8930] D: : lws_ensure_user_space: protocol pss 0, user_space=00007FF7F75DD190
[2022/08/30 16:05:41:8930] D: _realloc: size 132: client stash
[2022/08/30 16:05:41:8930] D: _realloc: size 984: ah struct
[2022/08/30 16:05:41:8930] D: _realloc: size 4096: ah data
[2022/08/30 16:05:41:8930] D: [wsicli|0|WS/h1/default/10.10.10.1]: __lws_set_timeout: 10 secs, reason 25
[2022/08/30 16:05:41:8930] D: [wsicli|0|WS/h1/default/10.10.10.1]: lws_http_client_connect_via_info2: stash 00000211B9CCDA00
[2022/08/30 16:05:41:8930] D: _realloc: size 11: strdup
[2022/08/30 16:05:41:8930] D: [wsicli|0|WS/h1/default/10.10.10.1]: lws_client_connect_2_dnsreq: new conn on no pipeline flag
[2022/08/30 16:05:41:8930] D: [wsicli|0|WS/h1/default/10.10.10.1]: lwsi_set_state: lwsi_set_state 0x10000200 -> 0x10000201
[2022/08/30 16:05:41:8930] D: _realloc: size 104: lws_sort_dns
[2022/08/30 16:05:41:8930] W: lws_plat_set_socket_options_ip: not implemented on windows platform
[2022/08/30 16:05:41:8930] D: [wsicli|0|WS/h1/default/10.10.10.1]: lws_client_connect_3_connect: WAITING_CONNECT
[2022/08/30 16:05:41:8930] D: [wsicli|0|WS/h1/default/10.10.10.1]: lwsi_set_state: lwsi_set_state 0x10000201 -> 0x10000202
[2022/08/30 16:05:41:8930] D: [wsicli|0|WS/h1/default/10.10.10.1]: __insert_wsi_socket_into_fds: tsi=0, sock=596, pos-in-fds=1
[2022/08/30 16:05:41:8930] D: [wsicli|0|WS/h1/default/10.10.10.1]: _lws_change_pollfd: fd 596 events 768 -> 768
[2022/08/30 16:05:41:8930] D: [wsicli|0|WS/h1/default/10.10.10.1]: __lws_set_timeout: 20 secs, reason 2
[2022/08/30 16:05:41:8950] D: [wsicli|0|WS/h1/default/10.10.10.1]: lws_client_connect_3_connect: connect: fd 596 errno: 10035
[2022/08/30 16:05:41:8950] D: [wsicli|0|WS/h1/default/10.10.10.1]: _lws_change_pollfd: fd 596 events 768 -> 784
[2022/08/30 16:05:41:8950] D: [wsicli|0|WS/h1/default/10.10.10.1]: lws_client_connect_via_info: adoption cb 19 to h1 lws-minimal-client
[2022/08/30 16:05:41:8950] D: _lws_state_transition: system: changed 1 'CONTEXT_CREATED' -> 2 'INITIALIZED'
[2022/08/30 16:05:41:8950] D: _lws_state_transition: system: changed 2 'INITIALIZED' -> 3 'IFACE_COLDPLUG'
[2022/08/30 16:05:41:8950] D: _lws_state_transition: system: changed 3 'IFACE_COLDPLUG' -> 4 'DHCP'
[2022/08/30 16:05:41:8950] D: _lws_state_transition: system: changed 4 'DHCP' -> 5 'CPD_PRE_TIME'
[2022/08/30 16:05:41:8960] D: _lws_state_transition: system: changed 5 'CPD_PRE_TIME' -> 6 'TIME_VALID'
[2022/08/30 16:05:41:8960] D: _lws_state_transition: system: changed 6 'TIME_VALID' -> 7 'CPD_POST_TIME'
[2022/08/30 16:05:41:8960] D: _lws_state_transition: system: changed 7 'CPD_POST_TIME' -> 8 'POLICY_VALID'
[2022/08/30 16:05:41:8960] D: _lws_state_transition: system: changed 8 'POLICY_VALID' -> 9 'REGISTERED'
[2022/08/30 16:05:41:8960] D: _lws_state_transition: system: changed 9 'REGISTERED' -> 10 'AUTH1'
[2022/08/30 16:05:41:8960] D: _lws_state_transition: system: changed 10 'AUTH1' -> 11 'AUTH2'
[2022/08/30 16:05:41:8969] D: _lws_state_transition: system: changed 11 'AUTH2' -> 12 'OPERATIONAL'
[2022/08/30 16:05:41:9331] D: [wsicli|0|WS/h1/default/10.10.10.1]: _lws_change_pollfd: fd 596 events 784 -> 768
[2022/08/30 16:05:41:9331] D: [wsicli|0|WS/h1/default/10.10.10.1]: lws_client_connect_3_connect: going into connect_4
[2022/08/30 16:05:41:9331] D: [wsicli|0|WS/h1/default/10.10.10.1]: lwsi_set_state: lwsi_set_state 0x10000202 -> 0x10000012
[2022/08/30 16:05:41:9340] D: [wsicli|0|WS/h1/default/10.10.10.1]: __lws_set_timeout: 15 secs, reason 8
[2022/08/30 16:05:41:9340] D: lws_http_client_socket_service: LRS_H1C_ISSUE_HANDSHAKE
[2022/08/30 16:05:41:9340] D: [wsicli|0|WS/h1/default/10.10.10.1]: _lws_change_pollfd: fd 596 events 768 -> 768
[2022/08/30 16:05:41:9340] D: lws_ssl_get_error: 00000211B9C9AB60 -1 -> 2 (errno 10035)
[2022/08/30 16:05:41:9350] D: [wsicli|0|WS/h1/default/10.10.10.1]: lwsi_set_state: lwsi_set_state 0x10000012 -> 0x10000204
[2022/08/30 16:05:41:9350] D: lws_client_create_tls: lws_ssl_client_connect1: 0
[2022/08/30 16:05:41:9740] D: lws_ssl_get_error: 00000211B9C9AB60 -1 -> 1 (errno 0)
[2022/08/30 16:05:41:9740] D: lws_ssl_client_connect2: SSL_connect says -1
[2022/08/30 16:05:41:9750] D: [wsicli|0|WS/h1/default/10.10.10.1]: __lws_close_free_wsi: real just_kill_connection A: (sockfd 596)
[2022/08/30 16:05:41:9750] D: [wsicli|0|WS/h1/default/10.10.10.1]: lwsi_set_state: lwsi_set_state 0x10000204 -> 0x10000020
[2022/08/30 16:05:41:9760] D: [wsicli|0|WS/h1/default/10.10.10.1]: __lws_vhost_unbind_wsi: vh default: count_bound_wsi 0
[2022/08/30 16:05:41:9760] D: [wsicli|0|WS/h1/default/10.10.10.1]: __lws_free_wsi: tsi fds count 1
[2022/08/30 16:05:43:0021] D: _realloc: size 1200: __lws_wsi_create_with_role
[2022/08/30 16:05:43:0021] D: : lws_role_transition: wsistate 0x200, ops (unset)
[2022/08/30 16:05:43:0030] D: : lws_vhost_bind_wsi: vh default: wsi none/none, count_bound_wsi 1
[2022/08/30 16:05:43:0030] D: _realloc: size 368: client ws struct
[2022/08/30 16:05:43:0040] D: : lws_role_transition: wsistate 0x10000200, ops h1
[2022/08/30 16:05:43:0040] D: : lws_ensure_user_space: protocol pss 0, user_space=00007FF7F75DD190
[2022/08/30 16:05:43:0040] D: _realloc: size 132: client stash
[2022/08/30 16:05:43:0040] D: _realloc: size 984: ah struct
[2022/08/30 16:05:43:0040] D: _realloc: size 4096: ah data
[2022/08/30 16:05:43:0050] D: [wsicli|1|WS/h1/default/10.10.10.1]: __lws_set_timeout: 10 secs, reason 25
[2022/08/30 16:05:43:0050] D: [wsicli|1|WS/h1/default/10.10.10.1]: lws_http_client_connect_via_info2: stash 00000211B9CCD400
[2022/08/30 16:05:43:0050] D: _realloc: size 11: strdup
[2022/08/30 16:05:43:0050] D: [wsicli|1|WS/h1/default/10.10.10.1]: lws_client_connect_2_dnsreq: new conn on no pipeline flag
[2022/08/30 16:05:43:0050] D: [wsicli|1|WS/h1/default/10.10.10.1]: lwsi_set_state: lwsi_set_state 0x10000200 -> 0x10000201
[2022/08/30 16:05:43:0050] D: _realloc: size 104: lws_sort_dns
[2022/08/30 16:05:43:0060] W: lws_plat_set_socket_options_ip: not implemented on windows platform
[2022/08/30 16:05:43:0060] D: [wsicli|1|WS/h1/default/10.10.10.1]: lws_client_connect_3_connect: WAITING_CONNECT
[2022/08/30 16:05:43:0060] D: [wsicli|1|WS/h1/default/10.10.10.1]: lwsi_set_state: lwsi_set_state 0x10000201 -> 0x10000202
[2022/08/30 16:05:43:0060] D: [wsicli|1|WS/h1/default/10.10.10.1]: __insert_wsi_socket_into_fds: tsi=0, sock=572, pos-in-fds=1
[2022/08/30 16:05:43:0069] D: [wsicli|1|WS/h1/default/10.10.10.1]: _lws_change_pollfd: fd 572 events 768 -> 768
[2022/08/30 16:05:43:0069] D: [wsicli|1|WS/h1/default/10.10.10.1]: __lws_set_timeout: 20 secs, reason 2
[2022/08/30 16:05:43:0069] D: [wsicli|1|WS/h1/default/10.10.10.1]: lws_client_connect_3_connect: connect: fd 572 errno: 10035
[2022/08/30 16:05:43:0069] D: [wsicli|1|WS/h1/default/10.10.10.1]: _lws_change_pollfd: fd 572 events 768 -> 784
[2022/08/30 16:05:43:0069] D: [wsicli|1|WS/h1/default/10.10.10.1]: lws_client_connect_via_info: adoption cb 19 to h1 lws-minimal-client
[2022/08/30 16:05:43:0450] D: [wsicli|1|WS/h1/default/10.10.10.1]: _lws_change_pollfd: fd 572 events 784 -> 768
[2022/08/30 16:05:43:0450] D: [wsicli|1|WS/h1/default/10.10.10.1]: lws_client_connect_3_connect: going into connect_4
[2022/08/30 16:05:43:0460] D: [wsicli|1|WS/h1/default/10.10.10.1]: lwsi_set_state: lwsi_set_state 0x10000202 -> 0x10000012
[2022/08/30 16:05:43:0460] D: [wsicli|1|WS/h1/default/10.10.10.1]: __lws_set_timeout: 15 secs, reason 8
[2022/08/30 16:05:43:0460] D: lws_http_client_socket_service: LRS_H1C_ISSUE_HANDSHAKE
[2022/08/30 16:05:43:0460] D: [wsicli|1|WS/h1/default/10.10.10.1]: _lws_change_pollfd: fd 572 events 768 -> 768
[2022/08/30 16:05:43:0460] D: lws_ssl_get_error: 00000211B9C9AB60 -1 -> 2 (errno 10035)
[2022/08/30 16:05:43:0460] D: [wsicli|1|WS/h1/default/10.10.10.1]: lwsi_set_state: lwsi_set_state 0x10000012 -> 0x10000204
[2022/08/30 16:05:43:0470] D: lws_client_create_tls: lws_ssl_client_connect1: 0
[2022/08/30 16:05:43:0863] D: lws_ssl_get_error: 00000211B9C9AB60 -1 -> 1 (errno 0)
[2022/08/30 16:05:43:0863] D: lws_ssl_client_connect2: SSL_connect says -1
[2022/08/30 16:05:43:0865] D: [wsicli|1|WS/h1/default/10.10.10.1]: __lws_close_free_wsi: real just_kill_connection A: (sockfd 572)
[2022/08/30 16:05:43:0875] D: [wsicli|1|WS/h1/default/10.10.10.1]: lwsi_set_state: lwsi_set_state 0x10000204 -> 0x10000020
[2022/08/30 16:05:43:0875] D: [wsicli|1|WS/h1/default/10.10.10.1]: __lws_vhost_unbind_wsi: vh default: count_bound_wsi 0
[2022/08/30 16:05:43:0875] D: [wsicli|1|WS/h1/default/10.10.10.1]: __lws_free_wsi: tsi fds count 1
[2022/08/30 16:05:45:2937] D: _realloc: size 1200: __lws_wsi_create_with_role
[2022/08/30 16:05:45:2937] D: : lws_role_transition: wsistate 0x200, ops (unset)
[2022/08/30 16:05:45:2937] D: : lws_vhost_bind_wsi: vh default: wsi none/none, count_bound_wsi 1
[2022/08/30 16:05:45:2947] D: _realloc: size 368: client ws struct
[2022/08/30 16:05:45:2947] D: : lws_role_transition: wsistate 0x10000200, ops h1
[2022/08/30 16:05:45:2947] D: : lws_ensure_user_space: protocol pss 0, user_space=00007FF7F75DD190
[2022/08/30 16:05:45:2947] D: _realloc: size 132: client stash
[2022/08/30 16:05:45:2947] D: _realloc: size 984: ah struct
[2022/08/30 16:05:45:2947] D: _realloc: size 4096: ah data
[2022/08/30 16:05:45:2957] D: [wsicli|2|WS/h1/default/10.10.10.1]: __lws_set_timeout: 10 secs, reason 25
[2022/08/30 16:05:45:2957] D: [wsicli|2|WS/h1/default/10.10.10.1]: lws_http_client_connect_via_info2: stash 00000211B9CCDA00
[2022/08/30 16:05:45:2957] D: _realloc: size 11: strdup
[2022/08/30 16:05:45:2957] D: [wsicli|2|WS/h1/default/10.10.10.1]: lws_client_connect_2_dnsreq: new conn on no pipeline flag
[2022/08/30 16:05:45:2957] D: [wsicli|2|WS/h1/default/10.10.10.1]: lwsi_set_state: lwsi_set_state 0x10000200 -> 0x10000201
[2022/08/30 16:05:45:2957] D: _realloc: size 104: lws_sort_dns
[2022/08/30 16:05:45:2966] W: lws_plat_set_socket_options_ip: not implemented on windows platform
Log with infinite checks lws_client_connect_check: 192.168.88.81
[2022/08/30 16:12:55:6015] U: LWS minimal ws client
[2022/08/30 16:12:55:6025] N: LWS: 4.3.0-unknown, NET CLI SRV H1 H2 WS ConMon IPv6-absent
[2022/08/30 16:12:55:6025] N:  ++ [wsi|0|pipe] (1)
[2022/08/30 16:12:55:6132] N:  ++ [vh|0|default||-1] (1)
[2022/08/30 16:12:55:6200] N: lws_plat_vhost_tls_client_ctx_init: Imported 51 certs from plat store
[2022/08/30 16:12:55:6210] D: [vh|0|default||-1]: lws_protocol_init_vhost: not instantiating lws-minimal-client
[2022/08/30 16:12:55:6220] D: _realloc: size 1200: __lws_wsi_create_with_role
[2022/08/30 16:12:55:6220] D: : lws_role_transition: wsistate 0x200, ops (unset)
[2022/08/30 16:12:55:6220] D: : lws_vhost_bind_wsi: vh default: wsi none/none, count_bound_wsi 1
[2022/08/30 16:12:55:6220] D: _realloc: size 368: client ws struct
[2022/08/30 16:12:55:6220] D: : lws_role_transition: wsistate 0x10000200, ops h1
[2022/08/30 16:12:55:6220] D: : lws_ensure_user_space: protocol pss 0, user_space=00007FF6D450D190
[2022/08/30 16:12:55:6220] D: _realloc: size 141: client stash
[2022/08/30 16:12:55:6220] D: _realloc: size 984: ah struct
[2022/08/30 16:12:55:6220] D: _realloc: size 4096: ah data
[2022/08/30 16:12:55:6220] D: [wsicli|0|WS/h1/default/192.168.88.81]: __lws_set_timeout: 10 secs, reason 25
[2022/08/30 16:12:55:6220] D: [wsicli|0|WS/h1/default/192.168.88.81]: lws_http_client_connect_via_info2: stash 0000029B2DC3B6E0
[2022/08/30 16:12:55:6220] D: _realloc: size 14: strdup
[2022/08/30 16:12:55:6220] D: [wsicli|0|WS/h1/default/192.168.88.81]: lws_client_connect_2_dnsreq: new conn on no pipeline flag
[2022/08/30 16:12:55:6220] D: [wsicli|0|WS/h1/default/192.168.88.81]: lwsi_set_state: lwsi_set_state 0x10000200 -> 0x10000201
[2022/08/30 16:12:55:6220] D: _realloc: size 104: lws_sort_dns
[2022/08/30 16:12:55:6220] W: lws_plat_set_socket_options_ip: not implemented on windows platform
[2022/08/30 16:12:55:6220] D: [wsicli|0|WS/h1/default/192.168.88.81]: lws_client_connect_3_connect: WAITING_CONNECT
[2022/08/30 16:12:55:6220] D: [wsicli|0|WS/h1/default/192.168.88.81]: lwsi_set_state: lwsi_set_state 0x10000201 -> 0x10000202
[2022/08/30 16:12:55:6220] D: [wsicli|0|WS/h1/default/192.168.88.81]: __insert_wsi_socket_into_fds: tsi=0, sock=604, pos-in-fds=1
[2022/08/30 16:12:55:6220] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 768 -> 768
[2022/08/30 16:12:55:6220] D: [wsicli|0|WS/h1/default/192.168.88.81]: __lws_set_timeout: 20 secs, reason 2
[2022/08/30 16:12:55:6230] D: [wsicli|0|WS/h1/default/192.168.88.81]: lws_client_connect_3_connect: connect: fd 604 errno: 10035
[2022/08/30 16:12:55:6230] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 768 -> 784
[2022/08/30 16:12:55:6230] D: [wsicli|0|WS/h1/default/192.168.88.81]: lws_client_connect_via_info: adoption cb 19 to h1 lws-minimal-client
[2022/08/30 16:12:55:6230] D: _lws_state_transition: system: changed 1 'CONTEXT_CREATED' -> 2 'INITIALIZED'
[2022/08/30 16:12:55:6240] D: _lws_state_transition: system: changed 2 'INITIALIZED' -> 3 'IFACE_COLDPLUG'
[2022/08/30 16:12:55:6240] D: _lws_state_transition: system: changed 3 'IFACE_COLDPLUG' -> 4 'DHCP'
[2022/08/30 16:12:55:6240] D: _lws_state_transition: system: changed 4 'DHCP' -> 5 'CPD_PRE_TIME'
[2022/08/30 16:12:55:6240] D: _lws_state_transition: system: changed 5 'CPD_PRE_TIME' -> 6 'TIME_VALID'
[2022/08/30 16:12:55:6249] D: _lws_state_transition: system: changed 6 'TIME_VALID' -> 7 'CPD_POST_TIME'
[2022/08/30 16:12:55:6249] D: _lws_state_transition: system: changed 7 'CPD_POST_TIME' -> 8 'POLICY_VALID'
[2022/08/30 16:12:55:6249] D: _lws_state_transition: system: changed 8 'POLICY_VALID' -> 9 'REGISTERED'
[2022/08/30 16:12:55:6249] D: _lws_state_transition: system: changed 9 'REGISTERED' -> 10 'AUTH1'
[2022/08/30 16:12:55:6259] D: _lws_state_transition: system: changed 10 'AUTH1' -> 11 'AUTH2'
[2022/08/30 16:12:55:6259] D: _lws_state_transition: system: changed 11 'AUTH2' -> 12 'OPERATIONAL'
[2022/08/30 16:12:56:6060] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 784 -> 768
[2022/08/30 16:12:56:6060] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 768 -> 784
[2022/08/30 16:12:56:6060] D: [wsicli|0|WS/h1/default/192.168.88.81]: lws_client_connect_check: errno 10037
[2022/08/30 16:12:56:6060] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 784 -> 768
[2022/08/30 16:12:56:6070] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 768 -> 784
[2022/08/30 16:12:56:6070] D: [wsicli|0|WS/h1/default/192.168.88.81]: lws_client_connect_check: errno 10037
[2022/08/30 16:12:56:6070] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 784 -> 768
[2022/08/30 16:12:56:6070] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 768 -> 784
[2022/08/30 16:12:56:6070] D: [wsicli|0|WS/h1/default/192.168.88.81]: lws_client_connect_check: errno 10037
[2022/08/30 16:12:56:6070] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 784 -> 768
[2022/08/30 16:12:56:6080] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 768 -> 784
[2022/08/30 16:12:56:6080] D: [wsicli|0|WS/h1/default/192.168.88.81]: lws_client_connect_check: errno 10037
[2022/08/30 16:12:56:6080] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 784 -> 768
[2022/08/30 16:12:56:6080] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 768 -> 784
[2022/08/30 16:12:56:6080] D: [wsicli|0|WS/h1/default/192.168.88.81]: lws_client_connect_check: errno 10037
[2022/08/30 16:12:56:6080] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 784 -> 768
[2022/08/30 16:12:56:6080] D: [wsicli|0|WS/h1/default/192.168.88.81]: _lws_change_pollfd: fd 604 events 768 -> 784

Arenoros avatar Aug 30 '22 13:08 Arenoros

I am seeing very similar issues with windows in the main branch, especially the infinite checks you describe.

I found that after removing this line https://github.com/warmcat/libwebsockets/blob/5b224c913f84767c7ef945bcb3ee28d8b7a5e0db/lib/core-net/client/connect3.c#L134 my client returned back to expected behavior.

I don't have a good explanation for this happening other than the the changes to the connect call here https://github.com/warmcat/libwebsockets/blob/5b224c913f84767c7ef945bcb3ee28d8b7a5e0db/lib/core-net/client/connect3.c#L113 has changed the behavior of lws_client_connect_check for windows clients. I think the connect call is correct now but the error handling after needs some updating to fix these issues.

Mitch-Martinez avatar Aug 30 '22 15:08 Mitch-Martinez

These are two different things getting mixed up.

  1. Server can't listen on the requested port

On Linux, he tries to wait in the background IIRC and if it becomes available he will pick up with it.

  1. Waiting for client connect

there is a pending patch here https://github.com/warmcat/libwebsockets/pull/2715 but AFAIK it doesn't address the spinning just changes the way to detect it to make it via select. If anyone is motivated to fix it, the problem is windows doesn't follow posix in that it should signal POLLOUT when the connect happens, and no events until / unless then or failure. So for windows, when it sees it is ongoing it should turn off POLLOUT and start a sul to recheck every 10ms or whatever (or if there is a better way, do that...)

lws-team avatar Aug 30 '22 15:08 lws-team

I see the mixup, sorry for that. I'll take a look at the PR, I'm motivated to fix it but I'm very much like a blind man when it comes to windows. Thanks for the info and support.

Mitch-Martinez avatar Aug 30 '22 17:08 Mitch-Martinez