configcat / node-sdk

ConfigCat SDK for Node.js. ConfigCat is a hosted feature flag service: https://configcat.com. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.
https://configcat.com/docs/sdk-reference/node
MIT License
19 stars 7 forks source link

6.5.7 cannot retrieve flags or settings #33

Closed clintonb closed 3 years ago

clintonb commented 3 years ago

Describe the bug

v6.5.7 is broken. After upgrading, and changing no config settings, my attempts to check flags fail:

2021-08-09T16:15:39.577Z | [error] Failed to download feature flags & settings from ConfigCat. Empty response from API. Error: connect ECONNREFUSED 127.0.0.1:443
2021-08-09T16:15:39.578Z | [info] Double-check your SDK Key on https://app.configcat.com/sdkkey
2021-08-09T16:15:44.495Z | [error] Failed to download feature flags & settings from ConfigCat. Empty response from API. Error: connect ECONNREFUSED 127.0.0.1:443
2021-08-09T16:15:44.495Z | [info] Double-check your SDK Key on https://app.configcat.com/sdkkey
2021-08-09T16:15:44.495Z | [error] JSONConfig is not present. Returning default value: 'false'.

Downgrading to 6.5.6 works. This issue was most likely a result of #32.

endret commented 3 years ago

Hi @clintonb ,

Thank you for the reporting.

Can you share you NODE version and the full initialisation code (without SDK key)?

Do you use any proxy settings?

Thanks, Endre

clintonb commented 3 years ago

Node v14.16.1

const config = require('config');  // node-config
const configcat = require('configcat-node');
const logger = require('../logger');  // winston

class FeatureFlag {
  static getClient() {
    return configcat.createClient(config.get('configCatKey'), {logger});
  }

  /**
   * Returns the value of a feature flag or setting based on its key.
   *
   * @param {String} key Flag name/identifier
   * @param {Boolean} defaultValue Default flag value (if not found
   * @param {String} userId ID of the authenticated user. This can be used for variation targeting.
   * @returns {Promise<Boolean>}
   */
  static async isEnabled(key, defaultValue = false, userId = undefined) {
    const userObject = userId ? {identifier: userId.toString()} : undefined;
    return FeatureFlag.getClient().getValueAsync(key, defaultValue, userObject);
  }
}

module.exports = FeatureFlag;
endret commented 3 years ago

Hi @clintonb

Thanks the code, I investigated your issue and identify these possible failures:

  1. Based on the error message (connect ECONNREFUSED 127.0.0.1:443) it looks like versioning problem and it is known issue about the got -> https://github.com/sindresorhus/got/issues/1572

  2. If you use the mentioned code in production and you have heavy load in your system it can occur similar issue because you create an configcat client every time when invoke isEnabled function. I recommend to apply any singleton solution to take advantage of internal caching mechanisms.

...

class FeatureFlag {

    static instance;

    static getClient() {
        if (!this.instance) {
            this.instance = configcat.createClient(config.get('configCatKey'), {logger});
        }

        return this.instance;
    }

...

Meanwhile I created a new release (6.5.8) with the previous got version, may you try with this in your application.

clintonb commented 3 years ago

6.5.8 works. Thanks!