Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atmosphere websocket is closed when disconnecting from network #922

Open
kevin-dp opened this issue Apr 17, 2019 · 3 comments
Open

Atmosphere websocket is closed when disconnecting from network #922

kevin-dp opened this issue Apr 17, 2019 · 3 comments

Comments

@kevin-dp
Copy link

I'm connected to my home network through wifi and run the Scalatra atmosphere example:

$ git clone https://github.com/scalatra/scalatra-website-examples.git
$ cd scalatra-website-examples/2.6/async/scalatra-atmosphere-example
$ chmod +x sbt
$ ./sbt ~jetty:start
...
Client 7f3d6651-6d68-49e6-958b-a41f1e45b4ae is connected

I open localhost:8080 in my browser (firefox 66.0.2) and everything works fine. However, when i turn off my wifi (i.e. i'm no longer connected to any network) the websocket between the frontend and the backend breaks:

Server disconnected the client 7f3d6651-6d68-49e6-958b-a41f1e45b4ae

I would expect the websocket to stay alive since the server is running locally on my machine.

On the other hand, this works:

  1. Turn off wifi (i.e. disconnect from the network)
  2. Launch the server ./sbt ~jetty:start
  3. Go to localhost:8080 --> everything works
  4. Turn on wifi --> continues to work
  5. Turn off wifi --> everything still works
@magnolia-k
Copy link
Contributor

What is the reason that it seems to keep working even if the network is disconnected?

It will be helpful if you can show the pointer that shows the behavior

@kevin-dp
Copy link
Author

Well, i don't know why the second scenario works.
But for the first scenario which is:

  1. Be connected on a network
  2. Launch the server ./sbt ~jetty:start
  3. Go to localhost:8080 --> works
  4. Disconnect from network --> website no longer works since websocket breaks

I guess that Atmosphere notices that we disconnected from the network and starts buffering the messages until we reconnect. This is somehow unexpected, since the server is running locally and, hence, is still reachable.

I will make a Dockerfile later today or tomorrow such that this problem can easily be reproduced.

@kevin-dp
Copy link
Author

kevin-dp commented Apr 23, 2019

In a Docker container (i.e. Linux) the problem does not occur, but on my Macbook (macOS high sierra 10.13.6) it does occur.

This is part of the server's output:

2019-04-23 16:42:58.924:INFO:oejs.AbstractConnector:main: Started ServerConnector@4ba380c7{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2019-04-23 16:42:58.925:INFO:oejs.Server:main: Started @3007ms
Client 74c36249-3be7-45bf-b38b-3c7dec98ca47 is connected
Server disconnected the client 74c36249-3be7-45bf-b38b-3c7dec98ca47

This is the client's console:

Invoking executeWebSocket
Using URL: ws://localhost:8080/the-chat?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.2.12-jquery&X-Atmosphere-Transport=websocket&Content-Type=application/json&X-atmo-protocol=true
Tue Apr 23 2019 16:43:04 GMT+0200 (Midden-Europese zomertijd) Atmosphere: websocket.onopen
Websocket successfully opened
Tue Apr 23 2019 16:43:04 GMT+0200 (Midden-Europese zomertijd) Atmosphere: websocket.onmessage: [object MessageEvent]
Tue Apr 23 2019 16:43:04 GMT+0200 (Midden-Europese zomertijd) Atmosphere: Firing onOpen
Tue Apr 23 2019 16:43:13 GMT+0200 (Midden-Europese zomertijd) Atmosphere: Firing onClose
Tue Apr 23 2019 16:43:13 GMT+0200 (Midden-Europese zomertijd) Atmosphere: Closed but not firing onClose

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/

XML Parsing Error: no root element found
Location: http://localhost:8080/the-chat?X-Atmosphere-Transport=close&X-Atmosphere-tracking-id=74c36249-3be7-45bf-b38b-3c7dec98ca47&_=1556030584409
Number 1, Column 1:

Tue Apr 23 2019 16:43:13 GMT+0200 (Midden-Europese zomertijd) Atmosphere: websocket.onclose
Websocket closed, reason: Unknown: no status code was provided even though one was expected.
Websocket closed, wasClean: true

When running the server inside a docker container i do not get the Synchronous XMLHttpRequest warning and XML Parsing Error: no root element found error. They only occur when running the server on my Macbook. So i guess, they have something to do with the websocket closing.

Client's console when running the server in a Docker container:

Invoking executeWebSocket
Using URL: ws://localhost:8081/the-chat?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.2.12-jquery&X-Atmosphere-Transport=websocket&Content-Type=application/json&X-atmo-protocol=true
Tue Apr 23 2019 16:51:20 GMT+0200 (Midden-Europese zomertijd) Atmosphere: websocket.onopen
Websocket successfully opened
Tue Apr 23 2019 16:51:20 GMT+0200 (Midden-Europese zomertijd) Atmosphere: websocket.onmessage: [object MessageEvent]
Tue Apr 23 2019 16:51:20 GMT+0200 (Midden-Europese zomertijd) Atmosphere: Firing onOpen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants