WebsocketServer failing to register onApplicationStart or via external hostname

Hi all, hoping someone can help with the following issue with Websocket registration using @isapir https://github.com/isapir/lucee-websocket.

I’ve gotten it working but the strange thing is that WebsocketServer(endpoint, listener) only works if I explicitly run it via localhost:8888 on the server Lucee runs (e.g., http://localhost:8888/testWs.cfm ). It doesn’t seem to register the WS if I run the same script via the fully qualified domain name. The domain name points to server with IIS frontend which proxies to the Lucee instance on the same server.

Furthermore, it also does NOT work if I include the WebsocketServer code in my onApplicationStart code. The endpoint appears to not be registered, but if I try to manually start it via my script using the external hostname, I get the following error in websockets.log:

Failed to register endpoint /ws/main/{channel}: Multiple Endpoints may not be deployed to the same path [/ws/main/{channel}] : existing endpoint was [class net.twentyonesolutions.lucee.websocket.LuceeEndpoint] and new endpoint is [class net.twentyonesolutions.lucee.websocket.LuceeEndpoint]"

After trying with external hostname above, if I then try to register it using localhost:8888 version, it then registers correctly.

Any thoughts on what’s happening and how to solve? It almost seems as if when using external hostname version, it is registering under a different name / port than the localhost:8888 version. However, I still don’t understand how / why the onApplicationStart version is not registered under the correct instance.

Regards,
Cage

Don’t forget to tell us about your stack!

OS: Windows Server 2016 (10.0) 64bit
Java Version: 11.0.4 (AdoptOpenJDK) 64bit
Tomcat Version: Apache Tomcat/9.0.24
Lucee Version: Lucee 5.3.8.206

Hi @psarin,

Take a look at this thread on the github page for the websocket extension - you may find it relevant:

You can only register a given websocketService using the same path once per server instance, regardless of the domain/host. Trying to register it again will give you the ‘Multiple Endpoints may not be deployed’ error. I worked around this by storing a reference to the registration using the ‘server’ scope, so that I could check to see if it was already defined before creating it.

I have also worked on a proxy system so that I can update the code for the listener without having to restart Lucee every time it changes. The details are in the github thread.

All the best,
Martin

1 Like

I’m not sure, but maybe the issue involving your onApplicationStart is the same I’ve experienced while experimenting with Lucee Rest components. I’ve seen that happening while enhancing this Rest documentation as a contribution..

What I believe or what I’ve seen happening is that Application.cfc doesn’t fire automatically on startup by itself. It only fires if a .cfm or .cfc is requested. So, if your are using plain ws protocol, Lucee won’t run any Application.cfc by any means., thus it also won’t invoke any onApplicationStart method. So, I’d use a cfm file (e.g. initWS.cfm that even may be an empty blank template) and use the scheduler to fire it on start up or similar.

Hi Martin,

Thanks for the response. Yes, I had looked at that thread prior to posting and am storing a reference to the websocket instance in Application scope. I will be using the code provided in the thread in the future as it seems quite useful.

However, between that thread and some other messages by @isapir, my understanding is that the message is just a warning message rather than a hard error message indicating multiple endpoints with same path are not allowed, and that it indicates the endpoint has been replaced / updated by the new listener.

In my case, deploying the app resulted in the websocket being created only when running from localhost:8888, rather than when running from the actual domain name. Running from the domain name always gave the above error, even on the first start.

In writing my question, it triggered a thought that perhaps I wasn’t referring to the correct hostname in my IIS URL rewrite rules. It appears that this was in fact the issue. My IIS URL rewrite was originally pointing to http://localhost:8888 rather than http://domain.name:8888. After changing it, everything works as expected! I imagine Lucee was starting the WS on localhost:8888 but when the request from domain.name came through, it was referred to the localhost:8888 version that already existed.

Regards,
Cage

1 Like

Hi Andreas,

Thanks for the response. In my scenario, the app was being triggered / started via call to the start web page. The issue (see my other message) was that my IIS URL rewriting was causing it to create the websocket server instance under localhost:8888 rather than my external domain.name:8888.

Regards,
Cage

Brilliant!! Glad that you got it working.