<div dir="ltr">Hello,<br><br>I have a problem when my client received websocket redirect response from server.<br><br>Scenario:<br>a. Connect to server with ip:A, port:B<br>b. Server response redirect information with ip:C, port:D<br>c. libwebsocket try to connect with lws_client_reset but failed due to LWS_ERRNO = 36 = LWS_EINPROGRESS and no more retry<br>d. Client received LWS_CALLBACK_CLIENT_CONNECTION_ERROR with reason "HS: Redirect failed."<br><br>If I stop client and change ip to C and port to D then run it, it can connect to server successfully.<br><br>I am using latest libwebsocket version.<br><br>How can I deal with this situation ? Any advice or something to try ?<br>Appreciate it.<br><br>----FAILED LOG-------------------------------------------------------<br>[ws_start_service]: websocket service starting ...<br><br>====== ws service info ======<br>host=10.70.50.187<br>port=80<br>path=/msg/fa07c9f0-d2ed-4636-83ad-d6f3bee0f452/00000000-0001-0001-0001-000000000008/BUZqudwFqzmwKF8fvMSu9FFb4TmTyqeb6RGf1ijd<br>==================<br><br>ws_callback: LWS_CALLBACK_PROTOCOL_INIT<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_ADD_POLL_FD<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_WSI_CREATE<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_GET_THREAD_ID<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD<br>ws_callback: LWS_CALLBACK_GET_THREAD_ID<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER<br>[2017/02/09 13:40:08:4191] NOTICE: Initial logging level 7<br>[2017/02/09 13:40:08:4191] NOTICE: Libwebsockets version: 2.1.0<br>[2017/02/09 13:40:08:4191] NOTICE: IPV6 not compiled in<br>[2017/02/09 13:40:08:4191] NOTICE: libev support not compiled in<br>[2017/02/09 13:40:08:4191] NOTICE: libuv support not compiled in<br>[2017/02/09 13:40:08:4191] NOTICE:  Threads: 4 each 2560 fds<br>[2017/02/09 13:40:08:4193] NOTICE:  mem: platform fd map: 81920 bytes<br>[2017/02/09 13:40:08:4193] NOTICE:  Compiled with OpenSSL support<br>[2017/02/09 13:40:08:4193] NOTICE:  SSL disabled: no LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT<br>[2017/02/09 13:40:08:4193] NOTICE: Creating Vhost 'default' port -1, 1 protocols, IPv6 off<br>[2017/02/09 13:40:08:4193] NOTICE:  mem: per-conn:          568 bytes + protocol rx buf<br>[2017/02/09 13:40:08:4193] NOTICE:  canonical_hostname = Mac-mini.local<br>[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_via_info2] 731 call lws_client_connect_2<br>[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_2][18] enter === <br>[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_2] 28<br>[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_2] 52 not proxy<br>[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_2] 60 socket server_addr4.sin_port=80<br>[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_2] 67 ads=10.70.50.187<br>[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_2] 119<br>[2017/02/09 13:40:08:4203] ERR: [lws_client_connect_2] 173 socket invalid = null<br>[2017/02/09 13:40:08:4203] ERR: [lws_client_connect_2] 185 socket bind again, valid not null !!!<br>[2017/02/09 13:40:08:4213] ERR: [lws_client_connect_2] 193 set wsi->mode = LWSCM_WSCL_WAITING_CONNECT<br>[2017/02/09 13:40:08:4213] ERR: [lws_client_connect_2] 210 past here, we can't simply free the structs as error handling as oom4 does.  We have to run the whole close flow.<br>[2017/02/09 13:40:08:4213] ERR: [lws_client_connect_2] 237 check again: socket valid o<br>[2017/02/09 13:40:08:4214] ERR: [lws_client_connect_2] 245 nonblocking connect retry (errno = 36)<br>[2017/02/09 13:40:08:4214] ERR: [lws_client_connect_2] 262 return wsi<br>[2017/02/09 13:40:08:4215] ERR: [lws_service_fd_tsi] 1140 call lws_client_socket_service<br>[2017/02/09 13:40:08:4215] ERR: [lws_client_socket_service] 85 wsi->mode=34<br>[2017/02/09 13:40:08:4215] ERR: [lws_client_socket_service] 89 LWSCM_WSCL_WAITING_CONNECT=34, call lws_client_connect_2<br>[2017/02/09 13:40:08:4215] ERR: we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE timeout protection set in client-handshake.c<br>[2017/02/09 13:40:08:4215] ERR: [lws_client_connect_2][18] enter === <br>[2017/02/09 13:40:08:4215] ERR: [lws_client_connect_2] 28<br>[2017/02/09 13:40:08:4215] ERR: [lws_client_connect_2] 52 not proxy<br>[2017/02/09 13:40:08:4215] ERR: [lws_client_connect_2] 60 socket server_addr4.sin_port=80<br>[2017/02/09 13:40:08:4215] ERR: [lws_client_connect_2] 67 ads=10.70.50.187<br>[2017/02/09 13:40:08:4215] ERR: [lws_client_connect_2] 119<br>[2017/02/09 13:40:08:4219] ERR: [lws_client_connect_2] 225 socket valid not null<br>[2017/02/09 13:40:08:4220] ERR: [lws_client_connect_2] 237 check again: socket valid o<br>[2017/02/09 13:40:08:4220] ERR: [lws_client_connect_2] 272 connected<br>[2017/02/09 13:40:08:4220] ERR: [lws_service_fd_tsi] 1140 call lws_client_socket_service<br>[2017/02/09 13:40:08:4220] ERR: [lws_client_socket_service] 85 wsi->mode=36<br>[2017/02/09 13:40:08:4220] ERR: [lws_client_socket_service] 144 LWSCM_WSCL_ISSUE_HANDSHAKE<br>[2017/02/09 13:40:08:4312] ERR: [lws_service_fd_tsi] 1143 goto handled<br>[2017/02/09 13:40:08:4312] ERR: [lws_service_fd_tsi] 1143 goto handled<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_DEL_POLL_FD<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_ADD_POLL_FD<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_WSI_CREATE<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD<br>ws_callback: LWS_CALLBACK_GET_THREAD_ID<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_CLIENT_CONNECTION_ERROR<br>[ws_callback] Connect with server error: HS: Redirect failed<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_DEL_POLL_FD<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>[2017/02/09 13:40:08:4361] ERR: [lws_service_fd_tsi] 1140 call lws_client_socket_service<br>[2017/02/09 13:40:08:4361] ERR: [lws_client_socket_service] 85 wsi->mode=40<br>[2017/02/09 13:40:08:4361] ERR: [lws_client_socket_service] 247 LWSCM_WSCL_WAITING_SERVER_REPLY<br>[2017/02/09 13:40:08:4365] ERR: [lws_client_socket_service] 315 call lws_client_interpret_server_handshake<br>[2017/02/09 13:40:08:4365] ERR: [lws_client_interpret_server_handshake] 470 http_response=301<br>[2017/02/09 13:40:08:4365] ERR: [lws_client_interpret_server_handshake] 485 call lws_client_reset, ads=10.70.50.187, port=8080, path=msg/fa07c9f0-d2ed-4636-83ad-d6f3bee0f452/00000000-0001-0001-0001-000000000008/BUZqudwFqzmwKF8fvMSu9FFb4TmTyqeb6RGf1ijd<br>[2017/02/09 13:40:08:4366] NOTICE: [lws_client_reset] 392 redirect ads='10.70.50.187', port=8080, path='msg/fa07c9f0-d2ed-4636-83ad-d6f3bee0f452/00000000-0001-0001-0001-000000000008/BUZqudwFqzmwKF8fvMSu9FFb4TmTyqeb6RGf1ijd'<br>[2017/02/09 13:40:08:4366] NOTICE: [lws_client_reset] 410 call lws_client_connect_2<br>[2017/02/09 13:40:08:4366] ERR: [lws_client_connect_2][18] enter === <br>[2017/02/09 13:40:08:4366] ERR: [lws_client_connect_2] 28<br>[2017/02/09 13:40:08:4366] ERR: [lws_client_connect_2] 52 not proxy<br>[2017/02/09 13:40:08:4366] ERR: [lws_client_connect_2] 60 socket server_addr4.sin_port=8080<br>[2017/02/09 13:40:08:4366] ERR: [lws_client_connect_2] 67 ads=10.70.50.187<br>[2017/02/09 13:40:08:4366] ERR: [lws_client_connect_2] 119<br>[2017/02/09 13:40:08:4370] ERR: [lws_client_connect_2] 173 socket invalid = null<br>[2017/02/09 13:40:08:4370] ERR: [lws_client_connect_2] 185 socket bind again, valid not null !!!<br>[2017/02/09 13:40:08:4370] ERR: [lws_client_connect_2] 193 set wsi->mode = LWSCM_WSCL_WAITING_CONNECT<br>[2017/02/09 13:40:08:4370] ERR: [lws_client_connect_2] 210 past here, we can't simply free the structs as error handling as oom4 does.  We have to run the whole close flow.<br>[2017/02/09 13:40:08:4371] ERR: [lws_client_connect_2] 237 check again: socket valid o<br>[2017/02/09 13:40:08:4371] ERR: [lws_client_connect_2] 245 nonblocking connect retry (errno = 36)<br>[2017/02/09 13:40:08:4371] ERR: [lws_client_connect_2] 262 return wsi<br>[2017/02/09 13:40:08:4371] ERR: [lws_client_interpret_server_handshake] 487 Redirect failed<br>[2017/02/09 13:40:08:4371] ERR: [lws_client_interpret_server_handshake] 488 check wsi->mode=34<br>ws_callback: LWS_CALLBACK_WSI_DESTROY<br>[2017/02/09 13:40:08:4387] ERR: [lws_service_fd_tsi] 1142 retrun 1<br><br>----SUCCESS LOG-------------------------------------------------------<br>[ws_start_service]: websocket service starting ...<br><br>====== ws service info ======<br>host=10.70.50.187<br>port=8080<br>path=/msg/fa07c9f0-d2ed-4636-83ad-d6f3bee0f452/00000000-0001-0001-0001-000000000008/BUZqudwFqzmwKF8fvMSu9FFb4TmTyqeb6RGf1ijd<br>==================<br><br>ws_callback: LWS_CALLBACK_PROTOCOL_INIT<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_ADD_POLL_FD<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_WSI_CREATE<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_GET_THREAD_ID<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD<br>ws_callback: LWS_CALLBACK_GET_THREAD_ID<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_LOCK_POLL<br>ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD<br>ws_callback: LWS_CALLBACK_UNLOCK_POLL<br>ws_callback: LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER<br>[2017/02/09 13:38:17:8137] NOTICE: Initial logging level 7<br>[2017/02/09 13:38:17:8137] NOTICE: Libwebsockets version: 2.1.0<br>[2017/02/09 13:38:17:8137] NOTICE: IPV6 not compiled in<br>[2017/02/09 13:38:17:8137] NOTICE: libev support not compiled in<br>[2017/02/09 13:38:17:8137] NOTICE: libuv support not compiled in<br>[2017/02/09 13:38:17:8138] NOTICE:  Threads: 4 each 2560 fds<br>[2017/02/09 13:38:17:8140] NOTICE:  mem: platform fd map: 81920 bytes<br>[2017/02/09 13:38:17:8143] NOTICE:  Compiled with OpenSSL support<br>[2017/02/09 13:38:17:8143] NOTICE:  SSL disabled: no LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT<br>[2017/02/09 13:38:17:8143] NOTICE: Creating Vhost 'default' port -1, 1 protocols, IPv6 off<br>[2017/02/09 13:38:17:8143] NOTICE:  mem: per-conn:          568 bytes + protocol rx buf<br>[2017/02/09 13:38:17:8145] NOTICE:  canonical_hostname = Mac-mini.local<br>[2017/02/09 13:38:17:8147] ERR: [lws_client_connect_via_info2] 731 call lws_client_connect_2<br>[2017/02/09 13:38:17:8150] ERR: [lws_client_connect_2][18] enter === <br>[2017/02/09 13:38:17:8150] ERR: [lws_client_connect_2] 28<br>[2017/02/09 13:38:17:8150] ERR: [lws_client_connect_2] 52 not proxy<br>[2017/02/09 13:38:17:8150] ERR: [lws_client_connect_2] 60 socket server_addr4.sin_port=8080<br>[2017/02/09 13:38:17:8150] ERR: [lws_client_connect_2] 67 ads=10.70.50.187<br>[2017/02/09 13:38:17:8150] ERR: [lws_client_connect_2] 119<br>[2017/02/09 13:38:17:8161] ERR: [lws_client_connect_2] 173 socket invalid = null<br>[2017/02/09 13:38:17:8162] ERR: [lws_client_connect_2] 185 socket bind again, valid not null !!!<br>[2017/02/09 13:38:17:8170] ERR: [lws_client_connect_2] 193 set wsi->mode = LWSCM_WSCL_WAITING_CONNECT<br>[2017/02/09 13:38:17:8171] ERR: [lws_client_connect_2] 210 past here, we can't simply free the structs as error handling as oom4 does.  We have to run the whole close flow.<br>[2017/02/09 13:38:17:8171] ERR: [lws_client_connect_2] 237 check again: socket valid o<br>[2017/02/09 13:38:17:8171] ERR: [lws_client_connect_2] 245 nonblocking connect retry (errno = 36)<br>[2017/02/09 13:38:17:8171] ERR: [lws_client_connect_2] 262 return wsi<br>[2017/02/09 13:38:17:8172] ERR: [lws_service_fd_tsi] 1140 call lws_client_socket_service<br>[2017/02/09 13:38:17:8172] ERR: [lws_client_socket_service] 85 wsi->mode=34<br>[2017/02/09 13:38:17:8172] ERR: [lws_client_socket_service] 89 LWSCM_WSCL_WAITING_CONNECT=34, call lws_client_connect_2<br>[2017/02/09 13:38:17:8173] ERR: we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE timeout protection set in client-handshake.c<br>[2017/02/09 13:38:17:8173] ERR: [lws_client_connect_2][18] enter === <br>[2017/02/09 13:38:17:8173] ERR: [lws_client_connect_2] 28<br>[2017/02/09 13:38:17:8173] ERR: [lws_client_connect_2] 52 not proxy<br>[2017/02/09 13:38:17:8173] ERR: [lws_client_connect_2] 60 socket server_addr4.sin_port=8080<br>[2017/02/09 13:38:17:8173] ERR: [lws_client_connect_2] 67 ads=10.70.50.187<br>[2017/02/09 13:38:17:8173] ERR: [lws_client_connect_2] 119<br>[2017/02/09 13:38:17:8177] ERR: [lws_client_connect_2] 225 socket valid not null<br>[2017/02/09 13:38:17:8177] ERR: [lws_client_connect_2] 237 check again: socket valid o<br>[2017/02/09 13:38:17:8177] ERR: [lws_client_connect_2] 272 connected<br>[2017/02/09 13:38:17:8177] ERR: [lws_service_fd_tsi] 1140 call lws_client_socket_service<br>[2017/02/09 13:38:17:8177] ERR: [lws_client_socket_service] 85 wsi->mode=36<br>[2017/02/09 13:38:17:8177] ERR: [lws_client_socket_service] 144 LWSCM_WSCL_ISSUE_HANDSHAKE<br>[2017/02/09 13:38:17:8222] ERR: [lws_service_fd_tsi] 1143 goto handled<br>[2017/02/09 13:38:17:8223] ERR: [lws_service_fd_tsi] 1143 goto handled<br>[2017/02/09 13:38:17:8336] ERR: [lws_service_fd_tsi] 1140 call lws_client_socket_service<br>[2017/02/09 13:38:17:8336] ERR: [lws_client_socket_service] 85 wsi->mode=40<br>[2017/02/09 13:38:17:8336] ERR: [lws_client_socket_service] 247 LWSCM_WSCL_WAITING_SERVER_REPLY<br>[2017/02/09 13:38:17:8338] ERR: [lws_client_socket_service] 315 call lws_client_interpret_server_handshake<br>[2017/02/09 13:38:17:8339] ERR: [lws_client_interpret_server_handshake] 470 http_response=101<br>[2017/02/09 13:38:17:8339] ERR: [lws_client_interpret_server_handshake] 864 set LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH<br>[2017/02/09 13:38:17:8339] ERR: [lws_service_fd_tsi] 1143 goto handled<br>ws_callback: LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH<br>ws_callback: LWS_CALLBACK_CLIENT_ESTABLISHED<br>[ws_callback] Connect with server success.<br>----------------------------------------------------------------------<br><br>Wayne<br></div>