R shiny server failed to run with apache proxy due to connection issue with certain websocket

2,251 views
Skip to first unread message

xiao xu

unread,
Nov 3, 2014, 11:40:45 PM11/3/14
to shiny-...@googlegroups.com
I set up the R shiny server with a apache proxy. The server will accept request from port 80 and forward it to port 3838

In my virtue host file I have the following:


        ProxyPass /shinyport/ http://localhost:3838/
        ProxyPassReverse /shinyport/ http://localhost:3838/
        RedirectMatch permanent ^/shinyport$ /shinyport/



and I have set up the R shiny configuration file accordingly, too

       server {
          listen 3838 127.0.0.1;
          .......
       }

However, when I run the R shiny app (in the directory of testapp under site_dir ) from firefox, the interface can be shown then it stop short with error message in java log:

Firefox can't establish a connection to the server at ws://[myservername]/shinyport/testapp/__sockjs__/883/iy9jjfoj/websocket.


I searched on line and found a similar experience  https://github.com/rstudio/ggvis/issues/219
which I followed and added the following in my virtue host configuration file

        <LocationMatch ^/testapp/_sockjs_/([0-9]+)/([a-z0-9]+)/websocket$>
                ProxyPassMatch ws://localhost:3838/testapp/_sockjs_/$1/$2/websocket
        </LocationMatch>

However, I still could not have it run and it popped up with the same (but slightly different) error message:

Firefox can't establish a connection to the server at ws://[myservername]/shinyport/testapp/__sockjs__/207/u3wk3o4d/websocket.


Can anyone give a suggestion where I did wrong? I tested the regular expression extensively and the syntax appears to be right. Why is that the proxy request from the websocket kept being blocked even I specified the LocationMatch?

Thanks

P.S. I am using the newest version of R shiny server, Rstudio server, apache and R (as well as ggplot2)


Fereshteh Karimeddini

unread,
Nov 5, 2014, 4:30:41 PM11/5/14
to shiny-...@googlegroups.com
Xiao,

I tried your proxy setup in my environment, and it is working fine. This is what I have:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        ProxyPass /shinyport/ http://localhost:3838/
        ProxyPassReverse /shinyport/ http://localhost:3838/shiny http://localhost:3838/
        RedirectMatch permanent ^/shinyport$ /shinyport/


- Can you try one of the Shiny example applications and see if that works?
- What version of Shiny Server are you running?
- What version of Shiny package are you running?
- What is the URL you are using to access your application?


Fereshteh

xiao xu

unread,
Nov 20, 2014, 5:31:24 PM11/20/14
to shiny-...@googlegroups.com
Dear Fereshteh
Thanks for your reply to my topic. Yes the ProxyPass has no problem and request from port 80 can be successfully forwarded to port 3838 on the server as I was able to open the R shiny app page.

The issue lies in the the subsequent execution of my R app in which it needs communication with the user side through websockets (probably because I was using a the ggplot2 library in my R app).
The error message I encountered is


Firefox can't establish a connection to the server at ws://[myservername]/shinyport/testapp/__sockjs__/883/iy9jjfoj/websocket.

Then I tried to address the issue by adding a regular expression ProxyPassMatch, inspired from the solution proposed in https://github.com/rstudio/ggvis/issues/219


<LocationMatch ^/testapp/_sockjs_/([0-9]+)/([a-z0-9]+)/websocket$>
                ProxyPassMatch ws://localhost:3838/testapp/_sockjs_/$1/$2/websocket
</LocationMatch>

Still, it does not work...basically port 80 can successfully forward user request to port 3838 but the subsequent websocket communication cannot established..

Is there a way to get around this problem?

Thanks a lot




Fereshteh Karimeddini

unread,
Nov 25, 2014, 1:23:47 PM11/25/14
to shiny-...@googlegroups.com
Xiao,

A couple of things you can try:

1- In your browser access your Shiny application and then try these keyboard combinations: Ctrl+Alt+Shint+A
This would show you a list of protocols (network methods) and their status (enabled or disabled). In my case I have all of them enabled. So if there is any problem with websockets, it can default to another protocol. If you see the non-websockets protocols as disabled, please enable and try again.

2- You can also use this configuration in your /etc/shiny-server/shiny-server.conf file:

disable_websockets;

Restart your Shiny Server and try again.

Let us know if neither of these solves the problem for you.

Best,
Fereshteh
Message has been deleted

Steven Beaupré

unread,
Dec 6, 2014, 8:28:26 PM12/6/14
to shiny-...@googlegroups.com
Dear Fareshteh,

I am experiencing the same issues.

I tried Xiao suggestion inspired from the RStudio Server runApp solution; not working.

I tried to disable websocket in the Shiny Server configuration file as well, yet.. still no chance..

Any idea on what I could try next ?

Fereshteh Karimeddini

unread,
Dec 8, 2014, 4:51:54 PM12/8/14
to shiny-...@googlegroups.com
Dear Steven,

- Are you also using a proxy server?
- Any errors in the /var/log/shiny-server.log file?
- What error(s) do you see in browser console?
- Can you try deploying your app to shinyapps.io and see if the behavior is the same?

Rajesh Chowdary

unread,
May 24, 2016, 5:00:04 AM5/24/16
to Shiny - Web Framework for R
is this issue solved. Facing the same. If it is resolved, can you please share your findings ?

Joe Cheng

unread,
May 24, 2016, 12:56:31 PM5/24/16
to Rajesh Chowdary, Shiny - Web Framework for R
Is your app actually failing? "Firefox can't establish a connection to the server at ws://[myservername]/shinyport/testapp/__sockjs__/207/u3wk3o4d/websocket" may also be a false positive because we use SockJS which tries to fall back to alternate protocols if websockets isn't supported by your network topology, but you will still see this message in the JS error log.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/03f57b3d-b579-48ea-91b9-4eb275a9fd97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rajesh Chowdary

unread,
May 25, 2016, 2:53:50 AM5/25/16
to Shiny - Web Framework for R, whatsu...@gmail.com
Yes I see the following error in browser console - its the case in both chrome as well as mozilla. Interestingly, it works fine with IE 11. Just wondering whats causing the issue in browsers other than IE. 

Connection closed. Info: {"type":"close","code":1006,"reason":"Server lost session","wasClean":false}

Karl Forner

unread,
Jun 1, 2016, 3:51:16 AM6/1/16
to Shiny - Web Framework for R
I have the same kind of problem, cf https://github.com/rstudio/shiny-server/issues/206

From the logs, there are RobustSockJS collision, and the shiny apps git disconnected.

Karl Forner

unread,
Jun 6, 2016, 4:38:52 AM6/6/16
to Shiny - Web Framework for R
But increasing app_init_timeout and app_idle_timeout in shiny-server.conf seem to improve greatly (still got some disconnections).
Reply all
Reply to author
Forward
0 new messages