isapir / lucee-websocket

Enables server WebSockets for Lucee via JSR-356 compliant servlet containers (e.g. Tomcat 8, Jetty 9.1, etc.)
GNU Lesser General Public License v2.1
17 stars 6 forks source link

Some problems I found with multiple socket connections #13

Open DrunkenMoose opened 6 years ago

DrunkenMoose commented 6 years ago

Hey,

First off all thanks for this library to use websockets within lucee! I find this new technique very interesting and making my own chat that I can integrate with different modules is very handy. I got myself into some trouble installing the websockets. I'm also made this thread: https://stackoverflow.com/questions/46489727/lucee-5-0-websocket-outside-localhost a while back. After opening port 8888 it started to work. Now I ran into another problem and thought maybe you can shine some light on it. Let me first explain how I constructed this.

Now I come across a problem that when the last active chat room is being called, gives weird response. It says that it's open, but if you try to send a message it does nothing.

After that I found that in an earlier message I got the following error:

The websocket session [156] has been closed (can only call close)

Now I thought maybe do I need to manually close the sessions? Because when I restart the whole server (where lucee is installed) it works again for all the active chat rooms. So it must be something with the websocket. And is websocket session [156] number 156 of the sessions? I only work with 3 different active channels so that must be weird then.

Also another small thing I found is that when you restart lucee itself, it gives a 500 server error on all the websocket channels. Don't know what that's about.

Hope you can help me out, if I can get it a bit more stable then this works amazing. Thanks! Roland M

DrunkenMoose commented 6 years ago

Some extra info:

I found something in your docs saying that when you leave the page the websocket javascript object will be destroyed. But that probably doesn't mean that the user automatically unsubscribe to the channel? I also found that when everybody is unsubscribed than it will close the session. I use the subscribed user list in the listener to pass along, so I know that works automatically.

But everytime I reload the application it must call the new WebSocket() function, because you cannot pass this object to all the clients connecting. But maybe I will need to write some code that unsubscribes a user when he leaves, so that the session is closed and will not build up on the server.

We also had some weird server performance. Suddenly we have memory leaks and higher CPU usage. We expanded some limits to get rid of this problem.

So this is just some extra info, still hope you can help me. Thanks

isapir commented 6 years ago

I'm sorry but I didn't get a chance yet to read the whole thing as I must leave the office, but:

When accessing the login screen of one of the open applications it registers the websocket on it's own 'parent' channel. Like this: WebsocketRegister("/ws/chat_corecdev/{channel}", new "connectors/ChatListener"()); With chat_corecdev as parent channel. I did this because I think it gives trouble if you register multiple websockets on the same parent channel?

You mean that you register the websocket each time someone goes to the login screen? If so, then change that first. You only need to register the websocket once. The only reason to re-register the websocket is if you modify the listener's code and you want to create an update version and re-register it.

I will try to look in depth at the rest of your question soon, but FWIW, it's better to ask questions in dev.lucee.org and only file bugs here once they're confirmed.

DrunkenMoose commented 6 years ago

Hey,

I don't really like dev.lucee.org, I think this is cleaner and a good place for a discussion. Also more people will look here so if they have the same problem then this is better.

But thanks for the quick response I have taken an other good look at it and have some more information.

I did the websocketregister in login because if I did any changes in the listener then I could easier update the code. But I changed it to one websocketregister for each domain in applicationstart. Still found some problems with connecting to the sockets. The one worked, the other one gave a 500 server error. In the other github post I found that it's because of a multiple websocket register. So I changed it to one connecter and now they can both connect to that one websocketregister. I just use other channels.

So I think the problem with connection issues is now solves, but still I think there is an other problem. Because I'm developing the chat I need to reload the page a lot. And I just notice that a lot if the time, how more your reload, how slower it goes.

I also mentioned this is my first post that maybe I need to close some sessions to not overflow the websocket connection. Can you maybe confirm this? Or did you notice the same? If I can get this with a stable connection then it will really help me.

isapir commented 6 years ago

I just notice that a lot if the time, how more your reload, how slower it goes

What get slower after reloads? No, I haven't noticed anything like that but please clarify what you mean.

chewymole commented 5 years ago

I am seeing a similar issue. We are using 2.0.3 version with lucee 5 with linux and tomcat. i register the channel in application start.

my users get a support channel per their user name (email address) so /ws/support/xuser@xuser.xxx each time the user loads a page, the user gets a new session in that same channel. So the channel above ends up with hundreds of subscribed sessions. but only 1 is valid. if i try to broadcast to the channel i get the same error reported above.

My question is what do i need to add to my listeners to stop duplicated session/subscriptions?

thanks