Bug 1002070 - ProxyServer doesn't pass Sec-WebSocket-Protocol on websockets requests
ProxyServer doesn't pass Sec-WebSocket-Protocol on websockets requests
Status: CLOSED CURRENTRELEASE
Product: OpenShift Online
Classification: Red Hat
Component: Containers (Show other bugs)
2.x
Unspecified Unspecified
medium Severity medium
: ---
: ---
Assigned To: Mrunal Patel
libra bugs
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-08-28 08:38 EDT by Marek Schmidt
Modified: 2015-05-14 19:27 EDT (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-09-19 12:48:25 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Package.json file for testing. (676 bytes, text/plain)
2013-09-12 13:12 EDT, Mrunal Patel
no flags Details
Server.js file for testing. (2.36 KB, application/javascript)
2013-09-12 13:13 EDT, Mrunal Patel
no flags Details

  None (edit)
Description Marek Schmidt 2013-08-28 08:38:49 EDT
Description of problem:

The node ProxyServer seems to strip the Sec-WebSocket-Protocol  header, which results in Python Autobahn WAMP not working.

e.g. the following log is seen by the app:

2013-08-28 07:12:11-0400 [HTTPChannelHixie76Aware,113,127.2.229.129] received HTTP request:
        
        GET /ws HTTP/1.1
        Connection: Upgrade
        Upgrade: websocket
        Sec-Websocket-Version: 13
        Host: 127.2.229.129:8080
        Sec-Websocket-Key: MTMtMTM3NzY4ODMzMTY1OA==
        
        
        
        
2013-08-28 07:12:11-0400 [HTTPChannelHixie76Aware,113,127.2.229.129] received HTTP status line in opening handshake : GET /ws HTTP/1.1
2013-08-28 07:12:11-0400 [HTTPChannelHixie76Aware,113,127.2.229.129] received HTTP headers in opening handshake : {'connection': u'Upgrade', 'upgrade': u'websocket', 'sec-websocket-version': u'13', 'host': u'127.2.229.129:8080', 'sec-websocket-key': u'MTMtMTM3NzY4ODMzMTY1OA=='}
2013-08-28 07:12:11-0400 [HTTPChannelHixie76Aware,113,127.2.229.129] Hybi protocol detected
2013-08-28 07:12:11-0400 [HTTPChannelHixie76Aware,113,127.2.229.129] failing WebSockets opening handshake ('this server only speaks WAMP')




while the browser sent something like:

Accept	text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding	gzip, deflate
Accept-Language	en-gb,en;q=0.5
Cache-Control	no-cache
Connection	keep-alive, Upgrade
Host	broken-maschmid.rhcloud.com:8000
Origin	http://broken-maschmid.rhcloud.com
Pragma	no-cache
Sec-WebSocket-Key	Af6M+OzGdk92dSu1bsZjCw==
Sec-WebSocket-Protocol	wamp
Sec-WebSocket-Version	13
Upgrade	websocket
User-Agent	Mozilla/5.0 (X11; Linux x86_64; rv:23.0) Gecko/20100101 Firefox/23.0



The workaround is to hack Autobahn to ignore the Sec-WebSocket-Protocol, so it doesn't fail with "this server only speaks WAMP".


See also

https://www.openshift.com/forums/openshift/websockets-with-nodejs
https://www.openshift.com/forums/openshift/jetty-8xx-diy-cartridge-issues-with-websocket

for people reporting the same problems.



I believe the core of the problem might be in node-proxy/lib/proxy/ProxyServer.js

where 

var proxy_ws = new WebSocket('ws://' + ws_endpoint + upg_requri, zheaders);

doesn't pass the "protocol" attribute from the original request.
Comment 2 Mrunal Patel 2013-09-11 11:08:51 EDT
Borrowing test case from the user reported issue on forum (https://www.openshift.com/forums/openshift/websockets-with-nodejs) -

1. Create a nodejs application.
2. Copy over server.js and package.json from https://github.com/jasonish/openshift-node-websocket
3. Modify server.js to use OPENSHIFT_NODEJS_IP instead of OPENSHIFT_INTERNAL_IP
   (same for PORT).
4. git push your changes.
5. Use the client.js from https://github.com/jasonish/openshift-node-websocket to test the server
   node client.js ws://app-ns.dev.rhcloud.com:8000/
6. Verify the client keeps on getting data till it is stopped.

(Without the fix, the client connection is immediately closed as the server expects to see Sec-Websocket-Protocol as "echo-server".
Comment 3 Meng Bo 2013-09-12 04:58:45 EDT
Tested on devenv_3776 with steps in comment#2,
The connection will closed immediately.

\> node client.js ws://no1-bmengdev.dev.rhcloud.com:8000/
Warning: Native modules not compiled.  XOR performance will be degraded.
Warning: Native modules not compiled.  UTF-8 validation disabled.
Connecting to ws://no1-bmengdev.dev.rhcloud.com:8000/
WebSocket client connected
echo-protocol Connection Closed
Comment 4 Mrunal Patel 2013-09-12 13:12:13 EDT
Created attachment 796953 [details]
Package.json file for testing.
Comment 5 Mrunal Patel 2013-09-12 13:13:02 EDT
Created attachment 796954 [details]
Server.js file for testing.
Comment 6 Mrunal Patel 2013-09-12 13:17:03 EDT
I just retested and it worked for me. I have attached the package.json and server.js file that I used for testing this. (Ignore the native code compilation error for websocket module that doesn't affect this test case.). Also, to debug
make sure the server is running after the push by tailing the ~/nodejs/logs/node.log
Comment 7 Meng Bo 2013-09-13 02:08:54 EDT
Check on devenv-stage_471, it works well now.
And maybe the last time I failed because I am connecting the server inside the app gear. 

# node client.js ws://no81-bmengdev.dev.rhcloud.com:8000/
Connecting to ws://no81-bmengdev.dev.rhcloud.com:8000/
WebSocket client connected
Received: '739888'
Received: '15523852'
Received: '16017545'
Received: '3351055'
Received: '4459250'
Received: '2018313'
Received: '4521020'
Received: '3021884'
Received: '14880327'
Received: '9231157'
Received: '4399874'
Received: '4083156'
Received: '8176787'
Received: '6908197'
Received: '11015009'
Received: '15859325'
Received: '771345'
Received: '11924669'
Received: '16454520'
Received: '15474892'
Received: '8429852'
Received: '2977346'
Received: '12174073'
Received: '12879463'
Received: '4589779'
Received: '3582465'
Received: '3438632'
Received: '10037830'
Received: '10095069'
Received: '15920846'

Note You need to log in before you can comment on or make changes to this bug.