Unleash / unleash-proxy

Unleash Proxy is used to safely integrate frontend application with Unleash in a secure and scaleable way.
https://docs.getunleash.io/sdks/unleash-proxy
Apache License 2.0
53 stars 43 forks source link

unleash-proxy crashes with 'version.trim is not a function' #185

Closed nicks closed 2 months ago

nicks commented 2 months ago

Describe the bug

Unleash proxy crashed over the weekend, seen in our logs:

2024-07-21 22:01:48.209 
unprocessed_log=  const s = parse(version.trim().replace(/^[=v]+/, ''), options)
2024-07-21 22:01:48.209 
unprocessed_log=                          ^
2024-07-21 22:01:48.209 
unprocessed_log=
2024-07-21 22:01:48.209 
unprocessed_log=TypeError: version.trim is not a function
2024-07-21 22:01:48.209 
unprocessed_log=    at clean (/unleash-proxy/node_modules/unleash-client/node_modules/semver/functions/clean.js:3:27)
2024-07-21 22:01:48.209 
unprocessed_log=    at isStrictSemver (/unleash-proxy/node_modules/unleash-client/lib/strategy/strategy.js:26:56)
2024-07-21 22:01:48.209 
unprocessed_log=    at SemverOperator (/unleash-proxy/node_modules/unleash-client/lib/strategy/strategy.js:60:27)
2024-07-21 22:01:48.209 
unprocessed_log=    at FlexibleRolloutStrategy.checkConstraint (/unleash-proxy/node_modules/unleash-client/lib/strategy/strategy.js:143:21)
2024-07-21 22:01:48.209 
unprocessed_log=    at FlexibleRolloutStrategy.checkConstraints (/unleash-proxy/node_modules/unleash-client/lib/strategy/strategy.js:153:38)
2024-07-21 22:01:48.209 
unprocessed_log=    at FlexibleRolloutStrategy.isEnabledWithConstraints (/unleash-proxy/node_modules/unleash-client/lib/strategy/strategy.js:164:21)
2024-07-21 22:01:48.209 
unprocessed_log=    at FlexibleRolloutStrategy.getResult (/unleash-proxy/node_modules/unleash-client/lib/strategy/strategy.js:167:30)
2024-07-21 22:01:48.209 
unprocessed_log=    at /unleash-proxy/node_modules/unleash-client/lib/client.js:101:37
2024-07-21 22:01:48.209 
unprocessed_log=    at Array.some (<anonymous>)
2024-07-21 22:01:48.209 
unprocessed_log=    at UnleashClient.isFeatureEnabled (/unleash-proxy/node_modules/unleash-client/lib/client.js:94:75)

Steps to reproduce the bug

Not sure yet how to repro, still digging, was hoping you might have a guess? might be bad data on the settings side

Expected behavior

proxy not to crash

Logs, error output, etc.

No response

Screenshots

No response

Additional context

No response

Unleash version

unleashorg/unleash-proxy:v1.2.0

Subscription type

None

Hosting type

None

SDK information (language and version)

No response

nicks commented 2 months ago

probably the simplest fix is to move the isStrictSemvar check here --

https://github.com/Unleash/unleash-client-node/blob/e61e55a3080b6ce12701831558d8121da68e3517/src/strategy/strategy.ts#L100

inside the try...catch block

nunogois commented 2 months ago

Hi @nicks, thank you for reporting this issue and for suggesting a solution. We have created a PR (https://github.com/Unleash/unleash-client-node/pull/648) that implements your suggested fix. Once the PR is merged, we plan to release a new version of the proxy that will include this fix.

By any chance, could you please share what your context looks like for this field? This information would help us ensure that we have covered this edge case in our tests.

Thank you again for your contribution. Your suggestion was spot on and should help prevent similar issues in the future.

Edit: This fix is now available in Unleash Proxy v1.4.4.

nicks commented 2 months ago

@nunogois wow, thank you for the quick fix!

How would I go about getting the context for this field? I mainly pulled this trace from server logs, I don't have much more context than that.