Bug 884626 - [US3054][FORK] Websocket support failed
Summary: [US3054][FORK] Websocket support failed
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: OKD
Classification: Red Hat
Component: Containers
Version: 2.x
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
: ---
Assignee: Mrunal Patel
QA Contact: libra bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-12-06 12:56 UTC by Jianwei Hou
Modified: 2015-05-14 23:03 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-12-19 19:26:06 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
server.js for Websocket Echo (1.31 KB, application/x-javascript)
2012-12-06 23:10 UTC, Ram Ranganathan
no flags Details

Description Jianwei Hou 2012-12-06 12:56:05 UTC
Description of problem:
Application does not support websocket after disabling xml pooling

Version-Release number of selected component (if applicable):
On fork_ami_US3054_323

How reproducible:
Always

Steps to Reproduce:
1. Create a nodejs application and embed mongodb-2.2
2. Follow https://github.com/ramr/pacman to setup application, using the dev/websockets branch
rhc app create ns nodejs-0.6
rhc cartridge add mongodb-2.2 -a ns
cd ns
git remote add upstream -t dev/websockets git://github.com/ramr/pacman.git
git pull -s recursive -X theirs upstream dev/websockets
modify server.js, disable "xhr-polling" in line #128, in this case, if websocket fails, the app won't function well
git push
3. Access app
  
Actual results:
Only the frame image is displayed, other images are not displayed, and I can not interact with this app via websocket 

Expected results:
Should be functioning well without xml http request polling considering websocket is supported

Additional info:
This application will switch to xhr-polling if websocket failed, so this is the reason I disable "xhr-polling", under this situation, the application can only function well when websocket works well, and I can know websocket is supported as expected.

Comment 1 Jianwei Hou 2012-12-06 13:13:04 UTC
For websocket supported applications, I guess users intend to create a websocket server application that will communicate with the websocket client.
In this situation, the server needs to find a port to bind to. 
$OPENSHIFT_INTERNAL_IP is 8080, and this is the port is used by our web application, so if I try to bind to this port, I will most likely get "address already in use" error. 

So I tried to bind a larger port, eg: 15001, after this, my websocket server starts well.
Problem I have encountered is my client does not seem to connect to it successfully via ws://n2-us3054t6.dev.rhcloud.com:8000/ 

My client is not a web browser, but a ruby client tool I used in terminal.

So my question is:
1. Can I bind to 15001 if I intend to develop my own websocket server
2. Should I only send websocket requests from browser instead of some ruby clients from terminal?

Thanks!

Comment 2 Ram Ranganathan 2012-12-06 23:10:07 UTC
What sort of an application is it? What's binding to port 8080 -- your app server?  Web sockets works over http[s], so the client would first need to negotiate an 
HTTP protocol based request and then upgrade to websockets.  8080 is the only application server port we currently expose out to talk HTTP. 
This is the case when you create a normal web application. 

 So what your 'app' and so the app server needs to do is take an 
HTTP request -- handle the protocol upgrade to web sockets and switch that connection/request to be handled as a web socket request. Both HTTP and WS work on port 8080 on the backend.  

 Now on the frontend side, which is how we route requests to $OPENSHIFT_INTERNAL_IP:8080 we only handle and route WS requests via the new proxy server running on port 8000/8443  (not the 80/443 version which is just apache). 

As re: your questions: 
1. We don't support any port for handling web traffic -- has to be 8080. This is 
   sorta similar to a normal web application written say in python ... 
    if you bind to 15000,  we don't route to that port -- we always route to 8080. 
    So you'd need to either use port 8080 on the gear or then you'd have to have
    an app server running on 8080, and then route to your custom port via 
    on some routing scheme e.g.   /abc15000/* uri would go to the server 
    on port 15000 via port 8080 on the gear. 
2. So what's the errors here? Maybe its something w/ the tool -- you can try using a utility called "wscat" which is already on the devenv to do testing.  That works for me. Also what does the app + ruby client do?

The simplest test would be to use an websocket echo server -- see attached sample. Steps to use it: 

1. rhc app create -l rr65 -p'' -a wsecho  -t nodejs-0.6
2. add 'ws' as a dependency to package.json 
  "dependencies": {
    "ws": "*"
  },

3.  cp over the attached server.js (as server.js for the app) 

4.  git add + commit + push

5.  You can then test it w/ the wscat utility on the devenv (or locally if 
     you install the 'ws' nodejs module) as follows:
        wscat -c  $uri  -- uri should be the app's url on port 8000 

sh$  wscat -c  http://wsecho-rr65.dev.rhcloud.com:8000/
connected (press CTRL+C to quit)
< websocket server app:  hello from wsapp
> yo
< OpenShift-WSEcho: yo
> wassup?
< OpenShift-WSEcho: wassup?

Comment 3 Ram Ranganathan 2012-12-06 23:10:55 UTC
Created attachment 659086 [details]
server.js for Websocket Echo

Comment 4 Jianwei Hou 2012-12-07 02:44:16 UTC
Verified on devenv_2564

Steps:
1. Create nodejs application, embed mongodb-2.2
rhc app create pacman nodejs-0.6
rhc cartridge add mongodb-2.2 -a pacman
2. Deploy quickstart to this app
cd pacman
git remote add upstream git://github.com/ramr/pacman.git
git pull -s recursive -X theirs upstream dev/websockets
3. Push changes to remote
git push
4. Visit website via 8000 port, and check logs
# tail -f /var/log/node-web-proxy/* 


Result:
App is working well
websocket traffics are logged:
<-------------snippet------------->
1354847697589:DEBUG:[Thu Dec 06 2012 21:34:57 GMT-0500 (EST)] - Handling HTTP[S] request to pacman-2564t.dev.rhcloud.com
1354847697589:DEBUG:[Thu Dec 06 2012 21:34:57 GMT-0500 (EST)] - Sending a proxy request to 127.0.250.129,8080
<-------------end------------->

The example from comment 2 also works well, Thanks!
[root@domU-12-31-39-00-E2-C1 ~]# wscat -c http://wsecho-2564t.dev.rhcloud.com:8000/
connected (press CTRL+C to quit)
< websocket server app:  hello from wsapp
> hi
< OpenShift-WSEcho: hi
> echo
< OpenShift-WSEcho: echo


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