[Libwebsockets] Websocket redirect failed question

黃小偉 zweblack at gmail.com
Thu Feb 9 07:40:26 CET 2017


Hello,

I have a problem when my client received websocket redirect response from
server.

Scenario:
a. Connect to server with ip:A, port:B
b. Server response redirect information with ip:C, port:D
c. libwebsocket try to connect with lws_client_reset but failed due to
LWS_ERRNO = 36 = LWS_EINPROGRESS and no more retry
d. Client received LWS_CALLBACK_CLIENT_CONNECTION_ERROR with reason "HS:
Redirect failed."

If I stop client and change ip to C and port to D then run it, it can
connect to server successfully.

I am using latest libwebsocket version.

How can I deal with this situation ? Any advice or something to try ?
Appreciate it.

----FAILED LOG-------------------------------------------------------
[ws_start_service]: websocket service starting ...

====== ws service info ======
host=10.70.50.187
port=80
path=/msg/fa07c9f0-d2ed-4636-83ad-d6f3bee0f452/00000000-0001-0001-0001-000000000008/BUZqudwFqzmwKF8fvMSu9FFb4TmTyqeb6RGf1ijd
==================

ws_callback: LWS_CALLBACK_PROTOCOL_INIT
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_ADD_POLL_FD
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_WSI_CREATE
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_GET_THREAD_ID
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD
ws_callback: LWS_CALLBACK_GET_THREAD_ID
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER
[2017/02/09 13:40:08:4191] NOTICE: Initial logging level 7
[2017/02/09 13:40:08:4191] NOTICE: Libwebsockets version: 2.1.0
[2017/02/09 13:40:08:4191] NOTICE: IPV6 not compiled in
[2017/02/09 13:40:08:4191] NOTICE: libev support not compiled in
[2017/02/09 13:40:08:4191] NOTICE: libuv support not compiled in
[2017/02/09 13:40:08:4191] NOTICE:  Threads: 4 each 2560 fds
[2017/02/09 13:40:08:4193] NOTICE:  mem: platform fd map: 81920 bytes
[2017/02/09 13:40:08:4193] NOTICE:  Compiled with OpenSSL support
[2017/02/09 13:40:08:4193] NOTICE:  SSL disabled: no
LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT
[2017/02/09 13:40:08:4193] NOTICE: Creating Vhost 'default' port -1, 1
protocols, IPv6 off
[2017/02/09 13:40:08:4193] NOTICE:  mem: per-conn:          568 bytes +
protocol rx buf
[2017/02/09 13:40:08:4193] NOTICE:  canonical_hostname = Mac-mini.local
[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_via_info2] 731 call
lws_client_connect_2
[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_2][18] enter ===
[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_2] 28
[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_2] 52 not proxy
[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_2] 60 socket
server_addr4.sin_port=80
[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_2] 67 ads=10.70.50.187
[2017/02/09 13:40:08:4194] ERR: [lws_client_connect_2] 119
[2017/02/09 13:40:08:4203] ERR: [lws_client_connect_2] 173 socket invalid =
null
[2017/02/09 13:40:08:4203] ERR: [lws_client_connect_2] 185 socket bind
again, valid not null !!!
[2017/02/09 13:40:08:4213] ERR: [lws_client_connect_2] 193 set wsi->mode =
LWSCM_WSCL_WAITING_CONNECT
[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.
[2017/02/09 13:40:08:4213] ERR: [lws_client_connect_2] 237 check again:
socket valid o
[2017/02/09 13:40:08:4214] ERR: [lws_client_connect_2] 245 nonblocking
connect retry (errno = 36)
[2017/02/09 13:40:08:4214] ERR: [lws_client_connect_2] 262 return wsi
[2017/02/09 13:40:08:4215] ERR: [lws_service_fd_tsi] 1140 call
lws_client_socket_service
[2017/02/09 13:40:08:4215] ERR: [lws_client_socket_service] 85 wsi->mode=34
[2017/02/09 13:40:08:4215] ERR: [lws_client_socket_service] 89
LWSCM_WSCL_WAITING_CONNECT=34, call lws_client_connect_2
[2017/02/09 13:40:08:4215] ERR: we are under
PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE timeout protection set in
client-handshake.c
[2017/02/09 13:40:08:4215] ERR: [lws_client_connect_2][18] enter ===
[2017/02/09 13:40:08:4215] ERR: [lws_client_connect_2] 28
[2017/02/09 13:40:08:4215] ERR: [lws_client_connect_2] 52 not proxy
[2017/02/09 13:40:08:4215] ERR: [lws_client_connect_2] 60 socket
server_addr4.sin_port=80
[2017/02/09 13:40:08:4215] ERR: [lws_client_connect_2] 67 ads=10.70.50.187
[2017/02/09 13:40:08:4215] ERR: [lws_client_connect_2] 119
[2017/02/09 13:40:08:4219] ERR: [lws_client_connect_2] 225 socket valid not
null
[2017/02/09 13:40:08:4220] ERR: [lws_client_connect_2] 237 check again:
socket valid o
[2017/02/09 13:40:08:4220] ERR: [lws_client_connect_2] 272 connected
[2017/02/09 13:40:08:4220] ERR: [lws_service_fd_tsi] 1140 call
lws_client_socket_service
[2017/02/09 13:40:08:4220] ERR: [lws_client_socket_service] 85 wsi->mode=36
[2017/02/09 13:40:08:4220] ERR: [lws_client_socket_service] 144
LWSCM_WSCL_ISSUE_HANDSHAKE
[2017/02/09 13:40:08:4312] ERR: [lws_service_fd_tsi] 1143 goto handled
[2017/02/09 13:40:08:4312] ERR: [lws_service_fd_tsi] 1143 goto handled
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_DEL_POLL_FD
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_ADD_POLL_FD
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_WSI_CREATE
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD
ws_callback: LWS_CALLBACK_GET_THREAD_ID
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_CLIENT_CONNECTION_ERROR
[ws_callback] Connect with server error: HS: Redirect failed
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_DEL_POLL_FD
ws_callback: LWS_CALLBACK_UNLOCK_POLL
[2017/02/09 13:40:08:4361] ERR: [lws_service_fd_tsi] 1140 call
lws_client_socket_service
[2017/02/09 13:40:08:4361] ERR: [lws_client_socket_service] 85 wsi->mode=40
[2017/02/09 13:40:08:4361] ERR: [lws_client_socket_service] 247
LWSCM_WSCL_WAITING_SERVER_REPLY
[2017/02/09 13:40:08:4365] ERR: [lws_client_socket_service] 315 call
lws_client_interpret_server_handshake
[2017/02/09 13:40:08:4365] ERR: [lws_client_interpret_server_handshake] 470
http_response=301
[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
[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'
[2017/02/09 13:40:08:4366] NOTICE: [lws_client_reset] 410 call
lws_client_connect_2
[2017/02/09 13:40:08:4366] ERR: [lws_client_connect_2][18] enter ===
[2017/02/09 13:40:08:4366] ERR: [lws_client_connect_2] 28
[2017/02/09 13:40:08:4366] ERR: [lws_client_connect_2] 52 not proxy
[2017/02/09 13:40:08:4366] ERR: [lws_client_connect_2] 60 socket
server_addr4.sin_port=8080
[2017/02/09 13:40:08:4366] ERR: [lws_client_connect_2] 67 ads=10.70.50.187
[2017/02/09 13:40:08:4366] ERR: [lws_client_connect_2] 119
[2017/02/09 13:40:08:4370] ERR: [lws_client_connect_2] 173 socket invalid =
null
[2017/02/09 13:40:08:4370] ERR: [lws_client_connect_2] 185 socket bind
again, valid not null !!!
[2017/02/09 13:40:08:4370] ERR: [lws_client_connect_2] 193 set wsi->mode =
LWSCM_WSCL_WAITING_CONNECT
[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.
[2017/02/09 13:40:08:4371] ERR: [lws_client_connect_2] 237 check again:
socket valid o
[2017/02/09 13:40:08:4371] ERR: [lws_client_connect_2] 245 nonblocking
connect retry (errno = 36)
[2017/02/09 13:40:08:4371] ERR: [lws_client_connect_2] 262 return wsi
[2017/02/09 13:40:08:4371] ERR: [lws_client_interpret_server_handshake] 487
Redirect failed
[2017/02/09 13:40:08:4371] ERR: [lws_client_interpret_server_handshake] 488
check wsi->mode=34
ws_callback: LWS_CALLBACK_WSI_DESTROY
[2017/02/09 13:40:08:4387] ERR: [lws_service_fd_tsi] 1142 retrun 1

----SUCCESS LOG-------------------------------------------------------
[ws_start_service]: websocket service starting ...

====== ws service info ======
host=10.70.50.187
port=8080
path=/msg/fa07c9f0-d2ed-4636-83ad-d6f3bee0f452/00000000-0001-0001-0001-000000000008/BUZqudwFqzmwKF8fvMSu9FFb4TmTyqeb6RGf1ijd
==================

ws_callback: LWS_CALLBACK_PROTOCOL_INIT
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_ADD_POLL_FD
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_WSI_CREATE
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_GET_THREAD_ID
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD
ws_callback: LWS_CALLBACK_GET_THREAD_ID
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_LOCK_POLL
ws_callback: LWS_CALLBACK_CHANGE_MODE_POLL_FD
ws_callback: LWS_CALLBACK_UNLOCK_POLL
ws_callback: LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER
[2017/02/09 13:38:17:8137] NOTICE: Initial logging level 7
[2017/02/09 13:38:17:8137] NOTICE: Libwebsockets version: 2.1.0
[2017/02/09 13:38:17:8137] NOTICE: IPV6 not compiled in
[2017/02/09 13:38:17:8137] NOTICE: libev support not compiled in
[2017/02/09 13:38:17:8137] NOTICE: libuv support not compiled in
[2017/02/09 13:38:17:8138] NOTICE:  Threads: 4 each 2560 fds
[2017/02/09 13:38:17:8140] NOTICE:  mem: platform fd map: 81920 bytes
[2017/02/09 13:38:17:8143] NOTICE:  Compiled with OpenSSL support
[2017/02/09 13:38:17:8143] NOTICE:  SSL disabled: no
LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT
[2017/02/09 13:38:17:8143] NOTICE: Creating Vhost 'default' port -1, 1
protocols, IPv6 off
[2017/02/09 13:38:17:8143] NOTICE:  mem: per-conn:          568 bytes +
protocol rx buf
[2017/02/09 13:38:17:8145] NOTICE:  canonical_hostname = Mac-mini.local
[2017/02/09 13:38:17:8147] ERR: [lws_client_connect_via_info2] 731 call
lws_client_connect_2
[2017/02/09 13:38:17:8150] ERR: [lws_client_connect_2][18] enter ===
[2017/02/09 13:38:17:8150] ERR: [lws_client_connect_2] 28
[2017/02/09 13:38:17:8150] ERR: [lws_client_connect_2] 52 not proxy
[2017/02/09 13:38:17:8150] ERR: [lws_client_connect_2] 60 socket
server_addr4.sin_port=8080
[2017/02/09 13:38:17:8150] ERR: [lws_client_connect_2] 67 ads=10.70.50.187
[2017/02/09 13:38:17:8150] ERR: [lws_client_connect_2] 119
[2017/02/09 13:38:17:8161] ERR: [lws_client_connect_2] 173 socket invalid =
null
[2017/02/09 13:38:17:8162] ERR: [lws_client_connect_2] 185 socket bind
again, valid not null !!!
[2017/02/09 13:38:17:8170] ERR: [lws_client_connect_2] 193 set wsi->mode =
LWSCM_WSCL_WAITING_CONNECT
[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.
[2017/02/09 13:38:17:8171] ERR: [lws_client_connect_2] 237 check again:
socket valid o
[2017/02/09 13:38:17:8171] ERR: [lws_client_connect_2] 245 nonblocking
connect retry (errno = 36)
[2017/02/09 13:38:17:8171] ERR: [lws_client_connect_2] 262 return wsi
[2017/02/09 13:38:17:8172] ERR: [lws_service_fd_tsi] 1140 call
lws_client_socket_service
[2017/02/09 13:38:17:8172] ERR: [lws_client_socket_service] 85 wsi->mode=34
[2017/02/09 13:38:17:8172] ERR: [lws_client_socket_service] 89
LWSCM_WSCL_WAITING_CONNECT=34, call lws_client_connect_2
[2017/02/09 13:38:17:8173] ERR: we are under
PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE timeout protection set in
client-handshake.c
[2017/02/09 13:38:17:8173] ERR: [lws_client_connect_2][18] enter ===
[2017/02/09 13:38:17:8173] ERR: [lws_client_connect_2] 28
[2017/02/09 13:38:17:8173] ERR: [lws_client_connect_2] 52 not proxy
[2017/02/09 13:38:17:8173] ERR: [lws_client_connect_2] 60 socket
server_addr4.sin_port=8080
[2017/02/09 13:38:17:8173] ERR: [lws_client_connect_2] 67 ads=10.70.50.187
[2017/02/09 13:38:17:8173] ERR: [lws_client_connect_2] 119
[2017/02/09 13:38:17:8177] ERR: [lws_client_connect_2] 225 socket valid not
null
[2017/02/09 13:38:17:8177] ERR: [lws_client_connect_2] 237 check again:
socket valid o
[2017/02/09 13:38:17:8177] ERR: [lws_client_connect_2] 272 connected
[2017/02/09 13:38:17:8177] ERR: [lws_service_fd_tsi] 1140 call
lws_client_socket_service
[2017/02/09 13:38:17:8177] ERR: [lws_client_socket_service] 85 wsi->mode=36
[2017/02/09 13:38:17:8177] ERR: [lws_client_socket_service] 144
LWSCM_WSCL_ISSUE_HANDSHAKE
[2017/02/09 13:38:17:8222] ERR: [lws_service_fd_tsi] 1143 goto handled
[2017/02/09 13:38:17:8223] ERR: [lws_service_fd_tsi] 1143 goto handled
[2017/02/09 13:38:17:8336] ERR: [lws_service_fd_tsi] 1140 call
lws_client_socket_service
[2017/02/09 13:38:17:8336] ERR: [lws_client_socket_service] 85 wsi->mode=40
[2017/02/09 13:38:17:8336] ERR: [lws_client_socket_service] 247
LWSCM_WSCL_WAITING_SERVER_REPLY
[2017/02/09 13:38:17:8338] ERR: [lws_client_socket_service] 315 call
lws_client_interpret_server_handshake
[2017/02/09 13:38:17:8339] ERR: [lws_client_interpret_server_handshake] 470
http_response=101
[2017/02/09 13:38:17:8339] ERR: [lws_client_interpret_server_handshake] 864
set LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH
[2017/02/09 13:38:17:8339] ERR: [lws_service_fd_tsi] 1143 goto handled
ws_callback: LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH
ws_callback: LWS_CALLBACK_CLIENT_ESTABLISHED
[ws_callback] Connect with server success.
----------------------------------------------------------------------

Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libwebsockets.org/pipermail/libwebsockets/attachments/20170209/ec1292eb/attachment-0001.html>


More information about the Libwebsockets mailing list