question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Websocket handshake error does not auto fallback to polling or other transport

See original GitHub issue

Note: for support questions, please use one of these channels: stackoverflow or slack

You want to:

  • report a bug
  • request a feature

Current behaviour

If websocket is supported by both browser and server but proxy or firewall disallow connection socket.io will stuck on handeshake failure forever, although polling is enabled on both side and would work without any problem.

Steps to reproduce (if the current behaviour is a bug)

Disallow websocket ws and wss connection in firewall and test, client will stuck on trying to connect via websocket. Or do following in server side code:

                const io = require('socket.io')(server, { transports: [
			//'websocket', 
			'flashsocket', 
			'htmlfile', 
			'xhr-polling', 
			'jsonp-polling', 
			'polling'
		] });

And Client side code:

	var socket = io(window.location.protocol + "//" + window.location.hostname.split(":")[0] + ":8443", { path: "/socket.io", transports: [
			'websocket',
			'flashsocket', 
			'htmlfile', 
			'xhr-polling', 
			'jsonp-polling', 
			'polling
		], 
		allowUpgrades: true
	});

Theoretically client should fail a few times and switch to any of the 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling', 'polling' and work just fine.

But instead client keep on trying to connect via websocket. image

Expected behaviour

After timeout or certain number of tries go back to polling or any other possible transport.

Setup

  • OS: Windows Server 2012 R2
  • browser: Chrome Version 54.0.2840.71 m (64-bit)
  • socket.io version: 1.5.0

Other information (e.g. stacktraces, related issues, suggestions how to fix)

Supply options to set limit on upgrade attempts or retries.

This behavior is very annoying since nobody can ensure the internet infrastructure in between can always support websocket while both server and client can do/allow websocket, e.g enterprise firewall and so on.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Haocencommented, Dec 23, 2016

I think it might want to do round-robin in a specific order? Or try a few times before switch to another transportation method? Well, that is another story then. So the first method in transportations array is the default method, got it.

0reactions
hutbercommented, Jan 17, 2017

Nice one guys, I will try and look at fixing my problem in a similar way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Force upgrade after fallback to polling? - socket.io
Socket.io correctly falls back to polling then, but it never seems to try to switch back to websockets again, even if it would...
Read more >
How it works | Socket.IO
js, or another programming language) is established with a WebSocket connection whenever possible, and will use HTTP long-polling as fallback.
Read more >
26. WebSocket Support - Spring
This is why Spring provides fallback options that emulate the WebSocket API as close as possible based on the SockJS protocol (version 0.3....
Read more >
WebSockets vs Long Polling - Medium
The usual AJAX request/response we're all used to doesn't keep the connection ... In a nutshell, WebSockets are a thin transport layer built...
Read more >
18 Using the WebSocket Protocol in WebLogic Server
Protocol fallback provides a mechanism for using an alternative transport ... A programmatic endpoint is not deployed automatically with the application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found