Unleash/unleash-client-node

client is ready but not registered or synchronized

ethanryan opened this issue · 7 comments

Describe the bug

We've recently updated some dependencies and realized we're no longer receiving our feature toggle values from Unleash.

Our app uses:

    "express": "^4.18.1",
    "next": "^13.0.6",
    "react": "^18.2.0",
    "unleash-client": "^3.16.0",

We call initialize in our custom server and are getting:
Error: Unleash Repository error: Response was not statusCode 2XX, but was 401

  const unleash =  initialize({
    url: 'url-here',
    appName: 'appName-here',
    instanceId: 'instanceId-here',
  })

Question: we don't currently have an apiToken declared in our FE code. Is the apiToken necessary?

Steps to reproduce the bug

No response

Expected behavior

No response

Logs, error output, etc.

No response

Screenshots

No response

Additional context

No response

Unleash version

"unleash-client": "^3.16.0",

Subscription type

None

Hosting type

None

SDK information (language and version)

No response

Hey, @ethanryan 👋🏼 That sounds like a strange issue your describing. Could you help me understand more about it? What versions did you upgrade from? And what version of Unleash are you using?

Is this a node app?

Question: we don't currently have an apiToken declared in our FE code. Is the apiToken necessary?

Does FE stand for front end here? What kind of front end is this? Is it related to the node app? In general, yes, you'll need an API token to connect a client to Unleash, but this is nothing new, so it seems strange that it should suddenly start happening.

Hi @thomasheartman, thanks for your reply.

Yes, FE stands for frontend.

This is a Next.js / React app, connecting to Unleash server-side in our customer server.js file.

We're using unleash-client version ^3.13.0.

We have a self-hosted instance of Unleash, using unleash-server version 3.6.0.

I don't know why we started seeing errors in our app, in both dev and production environments. We were doing:

unleash.on('warn', console.warn);
unleash.on('error', console.error);

warning: our-api-endpoint/api/client/register returning 401
and
error: Error: Unleash Repository error: Response was not statusCode 2XX, but was 401

I'm not sure why we started seeing errors. We upgraded to React 18 and Next 13 recently, it may have something to do with those upgrades.

I've actually got Unleash working again locally. I commented out the warn and error, and am using initialize instead of startUnleash. We get all our feature toggles in ready. We aren't passing customHeaders to initialize.

At least one of the examples shows startUnleash getting called without customHeaders:

https://github.com/Unleash/unleash-client-node/blob/main/examples/simple_start_unleash.js

Unleash is working locally now, the weird thing is that it is not working in a dev environment.

If you have any ideas, that would be greatly appreciated. Thanks!

Ah, okay, I think I understand a bit better now.

We're using unleash-client version ^3.13.0.

We have a self-hosted instance of Unleash, using unleash-server version 3.6.0.

Right. Did you also update the unleash-client dependency now, or was that done previously? Because if you haven't touched any of the Unleash-related packages, then it's very curious that something that used to work doesn't anymore.

Actually, you said in your second message that

We're using unleash-client version ^3.13.0.

But in the opening post, it says:

"unleash-client": "^3.16.0",

Did you just update that? Does it work if you use a previous version of the Unleash client (whichever one you used before you updated)?

Taking your last message as the state of things, here's my understanding of the situation. Can you tell me whether I've got it right?

  • You've got a running version of Unleash (3.6) and the node client (3.13) and have been using these successfully for a while. They have been running fine without API tokens.
  • You recently updated your React and Next dependencies, and this made Unleash start to throw errors.
  • Running it locally, you can make it work if you use initialize instead of startUnleash. It used to work with startUnleash.

Is that correct? Because if so, it doesn't sound like you've changed anything related to Unleash and that it just stopped working all of a sudden. But if you did update the unleash-client too, then that's a contender. However, it shouldn't change the response from the server.

Can you try and fetch features from the server on the command line? Does it work without an API key?

curl "<your-unleash>/api/client/features"

I did just update to the latest version of unleash-client on my feature branch, from 3.13.0 to 3.16.0, but that doesn't seem to make a difference. I reverted that change.

I can go to <our-unleash>/api/client/features directly in the browser and see the response, but running in the command line:

curl "<our-unleash>/api/client/features"

returns:

<html><body><h1>401 Unauthorized</h1>
You need a valid user and password to access this content.
</body></html>

Thanks again for your help @thomasheartman!

Issue appears to have been with trying to upgrade to latest version of unleash-client.

Reverting to "unleash-client": "^3.13.0" seems to have fixed the issues.

This is possibly related: https://www.getunleash.io/blog/post-mortem-a-bug-from-the-past

"How many were impacted?
It’s a bit hard to say, but it took almost a year from releasing Unleash v3.13.0 until someone reported this issue. This version was also the latest version for only 3 days before it was replaced by v3.14.0. So it’s safe to assume that not many of the long term Unleash users got the chance to upgrade to this version before it was superseded."

Although I'm not sure if that is related to "unleash-client" or "unleash-server".

And I'm still not sure what caused our issues in the first place, but using initialize instead of startUnleash appears to be working for now.

No worries; glad you made it work! But it's a little worrisome that it broke your application between 3.13 and 3.16. I'll have to look into that.

This is possibly related: https://www.getunleash.io/blog/post-mortem-a-bug-from-the-past
[...]
Although I'm not sure if that is related to "unleash-client" or "unleash-server".

Yeah, that's for Unleash itself (the "unleash-server" package), so it shouldn't come into play here.

And I'm still not sure what caused our issues in the first place, but using initialize instead of startUnleash appears to be working for now.

I also don't know what's happened here, but I'll see what I can find. If you have any more details (or other questions), don't hesitate to let me know 🙋🏼

So I've been looking over the diff between 3.13 and 3.16 now, and I don't immediately see anything that should cause this behavior.

Do you have a reproducible example of something that works with 3.13 but not with 3.16?