pusher / pusher-websocket-swift

Pusher Channels websocket library for Swift
https://pusher.com/channels
MIT License
273 stars 167 forks source link

Timeout on authentication endpoint puts pusher in an incorrect state #401

Closed amir20001 closed 2 years ago

amir20001 commented 2 years ago

Steps to reproduce

Timeout in authentication endpoint causes pusher to think its connected with out actually connecting to the channels.

Expected behavior

Unless a 401 or 403 is received I would expect a retry.

Actual behavior

These are the logs that we saw, it seems like the authentication endpoint timed out, but pusher's state is still set to "connected" . Which masks the error that has happened.

[api] [PUSHER DEBUG] Network connection became viable [pusher] Pusher state change from connecting to connected [api] [PUSHER DEBUG] Socket established with socket ID: 138063.8281662 [pusher] Status: Unknown Response: nil Data: nil [pusher] Pusher failed to subscribe to channel private-room-207 [failedToSubscribeToChannel(name:response:data:error:)] Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={_kCFStreamErrorCodeKey=60, NSUnderlyingError=0x2891de850 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en4, ipv4, dns, _kCFStreamErrorCodeKey=60, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask .<1246>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask .<1246>" ), NSLocalizedDescription=The request timed out., NSErrorFailingURLStringKey=, NSErrorFailingURLKey=, _kCFStreamErrorDomainKey=1} | Code: -1001 | Domain: NSURLErrorDomain | UserInfo: ["_NSURLErrorFailingURLSessionTaskErrorKey": LocalDataTask .<1246>, "_kCFStreamErrorCodeKey": 60, "_kCFStreamErrorDomainKey": 1, "_NSURLErrorRelatedURLSessionTaskErrorKey": <__NSSingleObjectArrayI 0x2b108cac0>( LocalDataTask .<1246> ) , "NSUnderlyingError": Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: en4, ipv4, dns, _kCFStreamErrorCodeKey=60, _kCFStreamErrorDomainKey=1}, "NSErrorFailingURLKey": , "NSErrorFailingURLStringKey": , "NSLocalizedDescription": The request timed out.] [PUSHER DEBUG] Ping sent [PUSHER DEBUG] Websocket received pong

Any improvements you suggest

Should retry on timeout. ...

benw-pusher commented 2 years ago

We do expose a subscription error event you can bind to, if this is encountered you can build your own retry mechanism for attempting to subscribe to the correct channel.