Socket issue with rasa webchat on HTTPS

I have bot deployed in aws with HTTPS and using rasa webchat script on one of my website which is also on HTTPS and I am getting the error on website for the bot to load.

WebSocket connection to 'wss://rasa-aws-url:82/socket.io/?EIO=4&transport=websocket&sid=FMfJTJy9o8KI15IbAAFH 'failed

and sometimes

WebSocket connection to 'wss://rasa-aws-url:82/socket.io/?EIO=4&transport=websocket&sid=dfSA6Yxg1H9z3BnvAAF1 ’ failed: Error during WebSocket handshake: Unexpected response code: 200

If I refresh the page sometimes the bot is loading and sometimes getting disconnected because of above error, and launcher image is also not loading and coming like image

Everything is working perfectly on local but when it deployed on HTTPS all the new issues are rising.

when the bot is getting disconnected the logs of rasa as follows

2021-10-22 08:44:03,746 [ERROR]  Exception in callback _ProactorBasePipeTransport._call_connection_lost(None)
handle: <Handle _ProactorBasePipeTransport._call_connection_lost(None) created at C:\Users\Administrator\Desktop\Python3.8.6 base\Python38\lib\asyncio\proactor_events.py:385>
source_traceback: Object created at (most recent call last):
  File "C:\Users\Administrator\Desktop\project\venv\lib\site-packages\rasa\core\run.py", line 220, in serve_application
    app.run(
  File "C:\Users\Administrator\Desktop\project\venv\lib\site-packages\sanic\app.py", line 1111, in run
    serve(**server_settings)
  File "C:\Users\Administrator\Desktop\project\venv\lib\site-packages\sanic\server.py", line 912, in serve
    loop.run_forever()
  File "C:\Users\Administrator\Desktop\Python3.8.6 base\Python38\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()
  File "C:\Users\Administrator\Desktop\Python3.8.6 base\Python38\lib\asyncio\base_events.py", line 570, in run_forever
    self._run_once()
  File "C:\Users\Administrator\Desktop\Python3.8.6 base\Python38\lib\asyncio\base_events.py", line 1851, in _run_once
    handle._run()
  File "C:\Users\Administrator\Desktop\Python3.8.6 base\Python38\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "C:\Users\Administrator\Desktop\Python3.8.6 base\Python38\lib\asyncio\proactor_events.py", line 385, in _loop_writing
    self._loop.call_soon(self._call_connection_lost, None)
Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\Python3.8.6 base\Python38\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "C:\Users\Administrator\Desktop\Python3.8.6 base\Python38\lib\asyncio\proactor_events.py", line 162, in _call_connection_lost
    self._sock.shutdown(socket.SHUT_RDWR)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

My bot script on website

 <script>
!(function () {
       let e = document.createElement("script"),
         t = document.head || document.getElementsByTagName("head")[0];
       (e.src ="https://cdn.jsdelivr.net/npm/rasa-webchat@1.0.1/lib/index.js"),
         (e.async = !0),
         (e.onload = () => {
           window.WebChat.default(
             {
               initPayload: '/greet',
               title: 'AI Assistant',
               socketPath: "/socket.io/",
               profileAvatar: 'logo.jpeg',
               openLauncherImage: 'logo.jpeg',
               socketUrl: "https://rasa-aws-url:82/",
               customData: { language: "en"},
               params: {storage: "session"},
             },
          );
         }),
         t.insertBefore(e, t.firstChild);
     })();
  </script>
Rasa Version      :         2.7.0
Minimum Compatible Version: 2.6.0
Rasa SDK Version  :         2.7.0
Rasa X Version    :         None
Python Version    :         3.8.7
python-engineio   :      4.2.1
python-socketio   :     5.4.0
websockets         :     8.1

I am not able to figure out where the root cause is and how to resolve and I know rasa webchat is handled by botfront, raised issues on their github with no luck, hoping someone else faced the issue and resolved it. Please help me.

What you use to make HTTPS?

I used Nginx Reverse proxy, and it works like charm

@InnoOmnia I am using Aws Load balancer and the SSL is from godaddy.

Ok, can not much help. have you tried to listen socket directly? Try this, replace testibotti2.omnia.fi with your bot name

curl --output testibotti2_socket_testi “http://testibotti2.omnia.fi:5007/socket.io/?EIO=4&transport=polling

Then open created file

cat testibotti2_socket_test

it should be like this

{“sid”:“a3bb9e2baf6445d5a20514fb14448059”,“upgrades”:[“websocket”],“pingTimeout”:60000,“pingInterval”:25000}

@InnoOmnia din’t get you and can you guide me where to run the mentioned commands?

Ok, I’m running Rasa chatbot in a webserver, where I have ubuntu 18.04 running. So I open SSH connection to webserver and put those command in linux shell.

How is your system?

@InnoOmnia I am using windows 10 system, running rasa on command prompt with a specific port like

rasa run -m models --enable-api --cors “*” --debug -p 82

and accessing this via aws-instance-ip_address:port_number_of_rasa

ok, can not much help on windows environment but few questions still

where you run you bot script?

@InnoOmnia The script is on one of my clients website(HTTPS).

ok, so you chatbot widget is calling this web address

socketUrl: “https://rasa-aws_url:82/”,

and also this port

socketPath: “/socket.io/”,

and then you have configured Rasa to use port 1234

rasa run -m models --enable-api --cors “*” --debug -p 1234

So where you tell that if request comes to port 82 how it goes to Rasa port 1234?

@InnoOmnia for demo I gave random port number, but I am using the same ports in script and rasa, let me edit the previous post

See this, any help? something about firewall/proxy settings

The handshake error and websocket connection errors are resolved, by changing the rasa port from HTTP/HTTPS to TCP at the Load balancer end.

So the chat bot works now?

@InnoOmnia Yes, bot worked before also but there was frequent message drop outs and connectivity issues I don’t see any error in console now, after changing to TCP which is stable.

1 Like

Hey, I understood your solution but how to mess with the load balancer of rasa… I couldn’t find any file regarding this to edit or I may be a blind. Can you help!

how to mess with the load balancer of rasa I did not understand what you mean.
If you are trying to open ports, you can go to ec2-instance under security edit inbound rules and add which port you want to open as TCP and if load balancer is connected to that instance ,go to your load balancer under listeners you can add.

Hi @bharath-madduri I am trying to do something very similar. The difference is that my bot is deployed on some official server (not aws, etc) with HTTPs and it has nothing to do with load balancer. Rest of the details are same as you mentioned for your case in the initial post. I am also facing same issue of the bot getting frequently connected and disconnected.

Any help in this regard.

hi i have the same problem, can you give me more detail. how to change to TCP

the rasa project port should be on TCP not https/http.