awslabs / aws-mobile-appsync-sdk-js

JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Apache License 2.0
921 stars 266 forks source link

Websocket connection error code 7 undefined #255

Closed arelaxend closed 4 years ago

arelaxend commented 6 years ago

Dear aws contributors,

{[DEBUG] 05:15.670 AuthClass - getting session failed: "No userPool"}
ConsoleLogger.js:84 [DEBUG] 05:15.672 Credentials - setting credentials for guest
ConsoleLogger.js:84 [DEBUG] 05:15.673 Credentials - No Cognito Federated Identity pool provided
ConsoleLogger.js:100 {[DEBUG] 05:15.691 AWSPinpointProvider - ensure credentials error: "No Cognito Federated Identity pool provided"}
ConsoleLogger.js:100 {[DEBUG] 05:15.691 AWSPinpointProvider - ensure credentials error: "No Cognito Federated Identity pool provided"}
ConsoleLogger.js:84 [DEBUG] 05:15.693 AWSPinpointProvider - cannot send events without credentials, applicationId or region
ConsoleLogger.js:84 [DEBUG] 05:15.695 AWSPinpointProvider - cannot send events without credentials, applicationId or region
paho-mqtt.js:1050 WebSocket connection to 'wss://a12t2jth1f5u55.iot.us-east-2.amazonaws.com/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=***us-east-2%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20180918T150516Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=0fe9185dda08b65f607bb5865f6298dbd2997d3a8c7bb32408849464c204b782&X-Amz-Security-Token=***' failed: Error in connection establishment: net::ERR_CERT_SYMANTEC_LEGACY
LibraryFactory.ClientImpl._doConnect @ paho-mqtt.js:1050
LibraryFactory.ClientImpl.connect @ paho-mqtt.js:886
Client.connect @ paho-mqtt.js:2025
(anonymous) @ subscription-handshake-link.js:117
SubscriptionHandshakeLink._this.connect @ subscription-handshake-link.js:116
SubscriptionHandshakeLink._this.connectAll @ subscription-handshake-link.js:105
localhost/:1 Uncaught (in promise) {invocationContext: undefined, errorCode: 7, errorMessage: "AMQJS0007E Socket error:undefined."}
paho-mqtt.js:1050 WebSocket connection to 'wss://a12t2jth1f5u55.iot.us-east-2.amazonaws.com/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=***us-east-2%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20180918T150516Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=fade74ad9480e7f09d5012e87cbc59208d05c8d554d72404a04024a58fd0bccc&X-Amz-Security-Token=***' failed: Error in connection establishment: net::ERR_CERT_SYMANTEC_LEGACY
LibraryFactory.ClientImpl._doConnect @ paho-mqtt.js:1050
LibraryFactory.ClientImpl.connect @ paho-mqtt.js:886
Client.connect @ paho-mqtt.js:2025
(anonymous) @ subscription-handshake-link.js:117
SubscriptionHandshakeLink._this.connect @ subscription-handshake-link.js:116
SubscriptionHandshakeLink._this.connectAll @ subscription-handshake-link.js:105
localhost/:1 Uncaught (in promise) {invocationContext: undefined, errorCode: 7, errorMessage: "AMQJS0007E Socket error:undefined."}
ConsoleLogger.js:84 [DEBUG] 05:21.345 Credentials - getting credentials
ConsoleLogger.js:84 [DEBUG] 05:21.346 Credentials - picking up credentials
ConsoleLogger.js:84 [DEBUG] 05:21.346 Credentials - getting new cred promise
ConsoleLogger.js:84 [DEBUG] 05:21.347 Credentials - checking if credentials exists and not expired
ConsoleLogger.js:84 [DEBUG] 05:21.347 Credentials - need to get a new credential or refresh the existing one
ConsoleLogger.js:84 [DEBUG] 05:21.348 AuthClass - Getting current user credentials
ConsoleLogger.js:84 [DEBUG] 05:21.349 AuthClass - Getting current session
ConsoleLogger.js:100 {[DEBUG] 05:21.349 AuthClass - getting session failed: "No userPool"}
ConsoleLogger.js:84 [DEBUG] 05:21.350 Credentials - setting credentials for guest
ConsoleLogger.js:84 [DEBUG] 05:21.350 Credentials - No Cognito Federated Identity pool provided
ConsoleLogger.js:100 {[DEBUG] 05:21.350 AWSPinpointProvider - ensure credentials error: "No Cognito Federated Identity pool provided"}
ConsoleLogger.js:84 [DEBUG] 05:21.351 AWSPinpointProvider - cannot send events without credentials, applicationId or region

Anyone got this error too ?? Can't figure out why, I have checked in other issues..

We are using the latest reactjs packages, still the subscription fails approx. 1 over 3 for every page refresh: A.

package.json:

  "dependencies": {
    "@babel/runtime": "^7.0.0",
    "apollo-client": "^2.4.2",
    "aws-amplify": "^1.1.1",
    "aws-amplify-react": "^2.0.2",
    "aws-appsync": "^1.3.4",
    "aws-appsync-react": "^1.1.4",
    "aws-sdk": "^2.316.0",
    "enzyme": "^3.6.0",
    "enzyme-adapter-react-16": "^1.5.0",
    "graphql": "^14.0.2",
    "graphql-tag": "^2.9.2",
    "node-sass-chokidar": "^1.3.3",
    "npm-run-all": "^4.1.3",
    "react": "^16.5.1",
    "react-apollo": "^2.1.11",
    "react-dom": "^16.5.1",
    "react-router-dom": "^4.3.1",
    "react-scripts": "^1.1.5"
  },

Result.js:

import OnCreate from "./GraphQL/OnCreate";
import QueryWithIndex from "./GraphQL/QueryWithIndex";
import { Component } from "react";
import { compose, graphql } from "react-apollo";

class ResultsT extends Component {
  render() {
    return (null);
  }
}

const Results = compose(
  graphql(
    QueryWithIndex, {
      props: ({ data: { subscribeToMore } }) => subscribeToMore({ document: OnCreate }),
    })
)(ResultsT);

export default Results;

App.js

import AppSync from "./AppSync";
import awsmobile from './aws-exports';
import Results from './Results';
import Amplify from 'aws-amplify';
import AWSAppSyncClient from "aws-appsync";
import { Rehydrated } from "aws-appsync-react";
import React, { Component } from "react";
import { ApolloProvider } from "react-apollo";

Amplify.configure(awsmobile);

window.LOG_LEVEL='DEBUG';

const client = new AWSAppSyncClient({
  url    : AppSync.graphqlEndpoint,
  region : AppSync.region,
  auth: {
        type: AppSync.authenticationType,
        apiKey: AppSync.apiKey
    },
    disableOffline: true
});

class App extends Component {
  render() {
    return (
      <Results />
    );
  }
}

const WithProvider = () => (
    <ApolloProvider client={client}>
        <Rehydrated>
            <App />
        </Rehydrated>
    </ApolloProvider>
);

export default WithProvider;

Index.js

import App from './App';
import React from 'react';
import ReactDOM from 'react-dom';

ReactDOM.render( <App />, document.getElementById('root') )
export default gql(`
  subscription {
    onCreate {
      __typename
      id
      awsIdentityId
    }
  }`
);
export default gql(`
  query($limit: Int, $nextToken: String) {
    queryWithIndex(limit: $limit, nextToken: $nextToken) {
      items {
        __typename
        id
        awsIdentityId
      }
      nextToken
    }
  }
`);
appwiz commented 6 years ago

Hi @arelaxend, could you share the operating system and browser version where you are seeing this error?

arelaxend commented 6 years ago

Hi @appwiz,

MacBookPro15,1 : macOS 10.13.6 (17G2307), Darwin 17.7.0
Google Chrome: Version 68.0.3440.106 (Build officiel) (64 bits)

It looks like it's working on Safari Version 12.0 (13606.2.11) 👍

Edit: well, I don't know much about the socket library mqttv3.1, so, my contribution won't prob. go any further, and you are 🥇(still, it looks like a very nice api)

appwiz commented 6 years ago

Thanks for the info. I'm looking into it to figure out what's going on.

elorzafe commented 5 years ago

Hi @arelaxend can you paste the keys of what is inside under aws-exports.js file. (so you replace the values with ####s)

arelaxend commented 5 years ago

@elorzafe Oups.. i've just seen your post. 🔢

// WARNING: DO NOT EDIT. This file is Auto-Generated by AWS Mobile Hub. It will be overwritten.

// Copyright 2017-2018 Amazon.com, Inc. or its affiliates (Amazon). All Rights Reserved.
// Code generated by AWS Mobile Hub. Amazon gives unlimited permission to
// copy, distribute and modify it.

// AWS Mobile Hub Project Constants
const awsmobile = {
    'aws_app_analytics': 'enable',
    'aws_cloud_logic': 'enable',
    'aws_cloud_logic_custom': [{"id":"###","name":"###","description":"","endpoint":"https://###.execute-api.us-east-2.amazonaws.com/prod","region":"us-east-2","paths":["/###"]}],
    'aws_cognito_identity_pool_id': '###',
    'aws_cognito_region': 'us-east-2',
    'aws_content_delivery': 'enable',
    'aws_content_delivery_bucket': '###',
    'aws_content_delivery_bucket_region': 'us-east-2',
    'aws_content_delivery_cloudfront': 'enable',
    'aws_content_delivery_cloudfront_domain': '###.cloudfront.net',
    'aws_custom_domains': [{"domain":"###.io","apiId":"###"}],
    'aws_mobile_analytics_app_id': '###',
    'aws_mobile_analytics_app_region': 'us-east-1',
    'aws_project_id': '###',
    'aws_project_name': '###',
    'aws_project_region': 'us-east-2',
    'aws_resource_name_prefix': '###',
    'aws_user_files': 'enable',
    'aws_user_files_s3_bucket': '###',
    'aws_user_files_s3_bucket_region': 'us-east-2',
}

export default awsmobile;
nicklaros commented 5 years ago

got this error when using it on nodejs

appwiz commented 5 years ago

Could you paste the stack trace please?

nicklaros commented 5 years ago

Query and Mutation works fine. But subscription failed.

LibraryFactory.ClientImpl._disconnected(), paho-mqtt.js:1617
LibraryFactory.ClientImpl._on_socket_error(), paho-mqtt.js:1450
anonymous(), paho-mqtt.js:181
onError(), event-target.js:128
emit(), events.js:182
EventEmitter.emit(), domain.js:442
abortHandshake(), websocket.js:648
req.on(), websocket.js:535
emit(), events.js:182
EventEmitter.emit(), domain.js:442
parserOnIncomingClient(), _http_client.js:546
parserOnHeadersComplete(), _http_common.js:109
socketOnData(), _http_client.js:432
emit(), events.js:182
EventEmitter.emit(), domain.js:442
addChunk(), _stream_readable.js:279
readableAddChunk(), _stream_readable.js:264
Readable.push(), _stream_readable.js:219
onread(), net.js:636
Async call from HTTPPARSER
init(), inspector_async_hook.js:27
emitInitNative(), async_hooks.js:137
tickOnSocket(), _http_client.js:619
onSocketNT(), _http_client.js:667
_tickCallback(), next_tick.js:63
Async call from TickObject
init(), inspector_async_hook.js:27
emitInitNative(), async_hooks.js:137
emitInitScript(), async_hooks.js:336
TickObject(), next_tick.js:86
nextTick(), next_tick.js:117
onSocket(), _http_client.js:655
ClientRequest(), _http_client.js:248
request(), https.js:272
get(), https.js:276
initAsClient(), websocket.js:514
WebSocket(), websocket.js:62
LibraryFactory.ClientImpl._doConnect(), paho-mqtt.js:1050
LibraryFactory.ClientImpl.connect(), paho-mqtt.js:886
Client.connect(), paho-mqtt.js:2025
anonymous(), subscription-handshake-link.js:117
SubscriptionHandshakeLink._this.connect(), subscription-handshake-link.js:116
SubscriptionHandshakeLink._this.connectAll(), subscription-handshake-link.js:105
_tickCallback(), next_tick.js:68
Async call from Promise.then
anonymous(), subscription-handshake-link.js:176
Subscription(), Observable.js:179
subscribe(), Observable.js:258
anonymous(), index.ts:24
_tickCallback(), next_tick.js:68
Async call from Promise.then
anonymous(), index.ts:23
Subscription(), Observable.js:179
subscribe(), Observable.js:258
anonymous(), auth-link.js:192
_tickCallback(), next_tick.js:68
Module.runMain(), loader.js:746
startup(), node.js:238
bootstrapNodeJSCore(), node.js:572
Async call from Promise.then
anonymous(), auth-link.js:191
Subscription(), Observable.js:179
subscribe(), Observable.js:258
anonymous(), complex-object-link.js:88
_tickCallback(), next_tick.js:68
Module.runMain(), loader.js:746
startup(), node.js:238
bootstrapNodeJSCore(), node.js:572
Async call from Promise.then
anonymous(), complex-object-link.js:87
Subscription(), Observable.js:179
subscribe(), Observable.js:258
anonymous(), client.js:120
_tickCallback(), next_tick.js:68
Module.runMain(), loader.js:746
startup(), node.js:238
bootstrapNodeJSCore(), node.js:572
Async call from Promise.then
anonymous(), client.js:119
Subscription(), Observable.js:179
subscribe(), Observable.js:258
anonymous(), QueryManager.ts:958
Subscription(), Observable.js:179
subscribe(), Observable.js:258
anonymous(), request-subscribe-on-update-setting.ts:20
fulfilled(), request-subscribe-on-update-setting.js:4
_tickCallback(), next_tick.js:68
Module.runMain(), loader.js:746
startup(), node.js:238
bootstrapNodeJSCore(), node.js:572
Async call from Promise.then
step(), request-subscribe-on-update-setting.js:6
anonymous(), request-subscribe-on-update-setting.js:7
__awaiter(), request-subscribe-on-update-setting.js:3
exports.default(), request-subscribe-on-update-setting.ts:9
anonymous(), index.ts:125
Module._compile(), loader.js:699
Module._extensions..js(), loader.js:713
Module.load(), loader.js:612
tryModuleLoad(), loader.js:551
Module._load(), loader.js:543
Module.runMain(), loader.js:744
startup(), node.js:238
bootstrapNodeJSCore(), node.js:572

Debugging it further 8 level up from stacktrace on req.on(), ws/lib/websocket.js:535 I got response with statusCode 403 and statusMessage "Forbidden"

nicklaros commented 5 years ago

Can't figure out why its forbidden on Subscription but success on Query and Mutation

philiiiiiipp commented 5 years ago

@nicklaros Did you ever figure out why this is happening?

kwoxford commented 5 years ago

I had to put it on hold for a while. I’m looking again at it this week.

However I’m certain that it’s subscriptions that are failing - I have 4 subscriptions and they all fall over at the same time with 4 error messages.

On 12 Nov 2018, at 09:39, Philipp Beau notifications@github.com wrote:

@nicklaros Did you ever figure out why this is happening?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

manueliglesias commented 5 years ago

If you are running subscriptions in node, try this:

From https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/286#issuecomment-437992801

This could be the version of the websocket lib you have installed in node as a specific polyfill is needed. If you look here: https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-node.html

You will see "ws": "^3.3.1".

Could you try the instructions listed on that page?

kwoxford commented 5 years ago

Aahhh!

I’ll try that. Thanks.

I’m building and testing in node but the final version is for Cordova / JavaScript. Will that make a difference?

Kim

On 12 Nov 2018, at 20:43, Manuel Iglesias notifications@github.com wrote:

If you are running subscriptions in node, try this:

From #286 (comment)

This could be the version of the websocket lib you have installed in node as a specific polyfill is needed. If you look here: https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-node.html

You will see "ws": "^3.3.1".

Could you try the instructions listed on that page?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

nicklaros commented 5 years ago

If you are running subscriptions in node, try this:

From #286 (comment)

This could be the version of the websocket lib you have installed in node as a specific polyfill is needed. If you look here: https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-node.html You will see "ws": "^3.3.1". Could you try the instructions listed on that page?

confirmed using ws lib version ^4.0.0 and it works fine. but not with ^5.0.0, I guess it is related with some major version breaking changes

RainoPikkarainen commented 5 years ago

Hi, found this issue when searching for AWS iot net::ERR_CERT_SYMANTEC_LEGACY

If the Symantec certificate distrust error is your problem, you could try to fix it by checking if you're using the old iot endpoint format (xxx.iot.region.amazonaws.com), and replace that with a new one (xxx-ats.iot.region.amazonaws.com): https://aws.amazon.com/blogs/iot/aws-iot-core-ats-endpoints/

I fixed my (unrelated) problem by getting a new endpoint with an Amazon Trust Services url: $ aws iot describe-endpoint --endpoint-type iot:Data-ATS

elorzafe commented 4 years ago

Closing this issue because of inactivity, please feel free to create a new issue if the problem persists.