Troubleshooting Lucee Websockets with IIS and ARR


#1

I’m trying to get @21Solutions websocket extension running on WIndows 2012 R2 using Application Request Routing (ARR 3) on IIS. In short, I’ve configured the Websockets Role on the server, and I’ve got a URL Rewrite rule setup to rewrite ^ws/([0-9a-zA-Z-_/]+)$ to ws://{HTTP_HOST}:8888/ws/{R:1} The server is sitting behind an AWS ALB.

Right now, IIS is returning a 502 error code for these requests, so I’m trying to figure out what’s is happening to the request and why I’m getting a 502.

I know the websocket request hits the IIS because the response header includes Server:Microsoft-IIS/8.5

Looking at the failed request logs, I get the error: There was a connection error while trying to route the request.

So, it looks like it never reaches tomcat. Any ideas? How can I figure out why there’s a connection error?


#2

I made some progress on this… instead of the rewriting to ws:// I am rewriting to http:// and now I’m getting the expected 101 returned status code for a successful websocket connection. I’ll post more info as I continue to test/debug.


#3

I got it working, but had to work through a few issues. For this post, I’ll avoid talking specifically about using and/or coding for the Lucee Websockets Extension (https://github.com/isapir/lucee-websocket). Prior to this post, I had websockets working in my dev environment going through Tomcat directly. My challenge was to see if I could get it running on Windows using IIS and ARR.

###Server Configuration###

  1. Windows 2012 R2, IIS 8.5

  2. Install the Application Request Routing module (version 3) to be used as a reverse proxy to Tomcat
    https://www.iis.net/downloads/microsoft/application-request-routing

  3. Install the URL Rewrite Filter to IIS
    https://www.iis.net/downloads/microsoft/url-rewrite

  4. Install the Websockets Role to IIS
    https://docs.microsoft.com/en-us/iis/configuration/system.webserver/websocket

  5. Lucee v5.2.2.71, Lucee Websockets Extension, v2.0.1

###IIS Settings###

  1. Configured ARR as a reverse proxy. After ARR is installed, restart IIS and you’ll see “Application Request Routing Cache” in the server home list. Click on that, and in the right pane, click on “Server Proxy Settings”. Check “Enable proxy” leaving all the default settings. Make sure “Reverse rewrite host in response headers” is checked.

  2. All my websocket endpoints go through /ws/{params}, so I setup a URL Rewrite rule to forward those incoming websocket requests directly to Tomcat:
    Pattern: ^ws/([0-9a-zA-Z-_/]+)$
    Rewrite to: http://{HTTP_HOST}:8888/ws/{R:1}

###Tomcat Settings###

I ran into an issue with compression using Firefox and Chrome, which I solved by disabling compression for websocket frames. I don’t completely understand this issue, and I don’t know what if there will be any overall performance issues with Tomcat/Lucee. All I know is that it worked.

Here’s where I learned about the issue:
https://stackoverflow.com/questions/33272786/websockets-on-tomcat-8-iis-8-with-arr-3-are-not-working.

Prior to making this change, websockets were being closed immediately after being opened in Firefox. In Chrome, no frames were being sent/received. So, I opened the Lucee-Tomcat Service Control, went to the Java tab, and added this to the Java Options:

-Dorg.apache.tomcat.websocket.DISABLE_BUILTIN_EXTENSIONS=true

###Other Tools###

It was helpful to turn on Failed Request Tracing:

Here are some other helpful articles:


#4

@Redtopia Did you ever faced issue
WebSocket is already in CLOSING or CLOSED state
is there any work around for that?


#5

Are you seeing that when you’re trying to open a connection? There is an issue that I am aware of that requires a restart of Lucee, where all websocket requests fail to connect, but I can’t remember the error that I get in the browser. The issue is here:

https://github.com/isapir/lucee-websocket/issues/10.

Does the problem go away after you restart Lucee?


#6

No @Redtopia it is happening while I am trying to send message using JS wsbroadcast.send('test') & it is happening on every time.


#7

Not sure how to help without seeing some code. I don’t use wsbroadcast.send(). I have seen that error condition before, but I can’t tell you exactly what causes it.

The best way I’ve found to debug problems with websockets is through logging. Make sure your channel is being opened correctly on the server, and log everything that comes through your websocket handler. Then in the browser, use the Network/Websockets tab in the Chrome dev tools to make sure you have an open connection prior to calling wsbroadcast.send(). Maybe there’s a problem with the way you initialize your javascript.


#8

I am trying the same example https://github.com/isapir/lucee-websocket/wiki/Example---Echo & connection closed immediately


#9

Tried that in another machine, it was working. So it might be issue at my laptop. Decided to reinstall IIS & it’s modules (ARR, URL rewrite, Websockets role) in Laptop & it worked. @Redtopia Thanks a lot for your support