aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.44k stars 2.13k forks source link

V6- Hub is not handling "No Internet" case #13215

Open rkvirajgupta opened 7 months ago

rkvirajgupta commented 7 months ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

GraphQL API

Amplify Version

v6

Amplify Categories

api

Backend

None

Environment information

``` # Put output below this line ```

Describe the bug

V6- Hub is not handling "No Internet" case.

Expected behavior

It should give an event that the connection is interrupted. Screenshot_1

Reproduction steps

setup hub connection with graphql subscription. after that Just connect with the mobile wifi and disable the mobile Internet connection(see attached image). you will not get any events for this that connection is established but there is no data transfer in it.

Code Snippet

Hub.listen('api', data => {
    const {payload} = data;
    if (payload.event === CONNECTION_STATE_CHANGE) {
      const connectionState = payload.data.connectionState;
      console.log(connectionState )
      if (connectionState === 'Connected' && isNetworkAvailable === false) {
        setIsNetworkAvailable(true);
      }
      if (
        connectionState == 'ConnectedPendingNetwork' ||
        connectionState == 'ConnectionDisrupted' ||
        connectionState == 'ConnectionDisruptedPendingNetwork'
      ) {
        setIsNetworkAvailable(false);
      }
    }
  });

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

rkvirajgupta commented 7 months ago

None of the below events are triggered in No-Internet case

Connected - Connected and working with no issues. ConnectedPendingDisconnect - The connection has no active subscriptions and is disconnecting. ConnectedPendingKeepAlive - The connection is open, but has missed expected keep-alive messages. ConnectedPendingNetwork - The connection is open, but the network connection has been disrupted. When the network recovers, the connection will continue serving traffic. Connecting - Attempting to connect. ConnectionDisrupted - The connection is disrupted and the network is available. ConnectionDisruptedPendingNetwork - The connection is disrupted and the network connection is unavailable. Disconnected - Connection has no active subscriptions and is disconnecting.

chrisbonifacio commented 7 months ago

Hi @rkvirajgupta can you let us know what operating system + browser you are using to reproduce this issue? Can you also confirm that your subscription is working before the connection is disabled?

If you have any code that we can use to reproduce the issue, please share that as well.

Lastly, by "No internet" case, are you referring to the Windows OS wifi task bar's description of "No internet"? Judging from the screenshot that seems to be the case but I wonder if you are able to reproduce this on a different device with no connection such as a mobile or macOS device.

rkvirajgupta commented 7 months ago

@chrisbonifacio The OS is windows 10 & broswer is chrome.

Can you also confirm that your subscription is working before the connection is disabled? Yes, the subscription restarts when the network is available in every case but the event is not coming in HUB

If you have any code that we can use to reproduce the issue, please share that as well. I already shared a code snippet where it should send me an event that the connection is interrupted similar to other internet connection issues(already shared refer to my 2nd comment).

Lastly, I generated this issue using a mobile hotspot connected to my laptop and then I switch off my mobile data (Internet connection), and only the hotspot was still active on my mobile. after that, you will see the attached screenshot type, No-Internet case.

Let me know if you have any other questions.

chrisbonifacio commented 6 months ago

Hi @rkvirajgupta, I think I was able to reproduce this issue on a Windows PC. I tried connecting to a mobile hotspot on my phone, disabled mobile data, and did not observe any events.

This may not be exclusive to Windows, I also tried on my MacBook and observed that if I try different things to disrupt the network connection, such as turning off WiFi, switching networks, or setting Network to Offline in my browser - all result in an event being emitted.

However, connecting to a mobile hotspot, and then turning off mobile data on the phone, did not result in any new events. The Hub stayed hanging on ConnectionDisruptedPendingNetwork despite my laptop having already re-connected to my home WiFi.

image

Perhaps the issue has something to do with mobile hot spots in particular. I'll label this as a bug for further investigation by the team.

rkvirajgupta commented 6 months ago

Thanks @chrisbonifacio