1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
Unleash is the open source feature toggle service.
Go to file
Simon Hornby 5088409c4d
fix: polling in proxy repository now stops correctly (#3268)
### What

This patches two very subtle bugs in the proxy repository that cause it
to never actually stop polling the db in the background

## Details - Issue 1

We've recently started to get the following output when running `yarn
test`:

` Attempted to log "Error: Unable to acquire a connection
at Object.queryBuilder
(/home/simon/dev/unleash/node_modules/knex/lib/knex-builder/make-knex.js:111:26)`
        
This seems to occur for every test suite after running the proxy tests
and the full stack trace doesn't point to anything related to the
running tests that produce this output. Running a `git bisect` points to
this commit:
6e44a65c58
being the culprit but I believe that this may have surfaced the bug
rather than causing it.

Layering in a few console logs and running Unleash, seems to point to
the proxy repository setting up data polling but never actually
terminating it when `stop` was called, which is inline with the output
here - effectively the tests were continuing to run the polling in the
background after the suite had exited and jest freaks out that an async
task is running when it shouldn't be. This is easy to reproduce once the
console logs are in place in the `dataPolling` function, by running
Unleash - creating and deleting a front end token never terminates the
poll cycle.

I believe the cause here is some subtlety around using async functions
with timers - stop was being called, which results in the timer being
cleared but a scheduled async call was already on the stack, causing the
recursive call to resolve after stop, resurrecting the timer and
reinitializing the poll cycle.

I've moved the terminating code into the async callback. Which seems to
solve the problem here.

## Details - Issue 2

Related to the first issue, when the proxy service stops the underlying
Unleash Client, it never actually calls destroy on the client, it only
removes it from its internal map. That in turn means that the Client
never calls stop on the injected repository, it only removes it from
memory. However, the scheduled task is `async` and `unref`, meaning it
continues to spin in the background until every other process also
exits. This is patched by simply calling destroy on the client when
cleaning up

## The Ugly

This is really hard to test effectively, mostly because this is an issue
caused by internals within NodeJS and async. I've added a test that
reads the output from the debug log (and also placed a debug log in the
termination code). This also requires the test code to wait until the
async task completes. This is horribly fragile so if someone has a
better idea on how to prove this I would be a very happy human.

The second ugly part is that this is a subtle issue in complex code that
really, really needs to work correctly. I'm nervous about making changes
here without lots of eyes on this
2023-03-10 10:03:32 +02:00
.do
.github chore(deps): update lycheeverse/lychee-action action to v1.6.1 (#3283) 2023-03-09 17:49:57 +00:00
.husky
coverage feat: Instance stats for export/import (#3121) 2023-02-15 14:39:16 +02:00
docker chore(deps): bump http-cache-semantics from 4.1.0 to 4.1.1 in /docker (#3045) 2023-02-10 10:58:43 +01:00
docs/api/oas docs: Remove/update references to Heroku (#2099) 2022-10-19 12:02:00 +00:00
examples
frontend fix: hide change password when simple auth is disabled (#3282) 2023-03-09 14:13:40 +01:00
perf
scripts chore(deps): update dpage/pgadmin4 docker tag to v6.20 (#3128) 2023-02-16 18:38:59 +01:00
src fix: polling in proxy repository now stops correctly (#3268) 2023-03-10 10:03:32 +02:00
website docs: login history (#3261) 2023-03-08 19:08:50 +00:00
.dockerignore
.editorconfig Move e2e tests from frontend to backend .github (#1975) 2022-08-29 12:25:11 +00:00
.eslintignore Feat/add change request settings (#2390) 2022-11-11 10:09:25 +02:00
.eslintrc fix: remove stray only (#2589) 2022-12-02 13:10:39 +01:00
.gitignore docs: auto-generate remaining server-side SDK docs (#2858) 2023-01-13 12:40:28 +01:00
.lycheeignore chore: ignore Twitter link from being checked (#2971) 2023-01-23 22:09:28 +01:00
.node-version chore(deps): update node.js to v14.21.3 (#3223) 2023-03-01 18:18:31 +00:00
.nvmrc
.prettierignore
app.json fix: tell heroku to not build in production mode 2022-10-18 21:35:50 +02:00
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
docker-compose.yml Update docker-compose.yml (#3256) 2023-03-06 14:30:28 +01:00
Dockerfile Fix docker build (#2326) 2022-11-03 15:02:20 +01:00
LICENSE
package.json 4.22.0-beta.53 2023-03-09 15:20:34 +00:00
README.md added flutter documentation (#2736) 2023-01-03 13:07:01 +01:00
renovate.json feat: wait for deps to be somewhat stable (#2768) 2023-01-05 12:45:48 +01:00
tsconfig.json chore: attempt to make tsconfig stricter (#3077) 2023-02-28 08:12:32 +00:00
yarn.lock chore(deps): update dependency @types/node to v16.18.14 (#3280) 2023-03-09 09:22:10 +00:00

About Unleash

Unleash is an open source feature management solution. It improves the workflow of your development team and leads to quicker software delivery. Unleash increases efficiency and gives teams full control of how and when they enable new functionality for end users. Unleash lets teams ship code to production in smaller releases whenever they want.

Feature toggles make it easy to test how your code works with real production data without the fear that you'll accidentally break your users' experience. It also helps your team work on multiple features in parallel without each maintaining an separate feature branch.

Unleash is the largest open source solution for feature flagging on GitHub. There's 12 official client and server SDKs and 10+ community SDKs available; you can even make your own if you want to. You can use Unleash with any language and any framework.


Get started in 2 steps

1. Start Unleash

With git and docker installed, it's easy to get started:

Run this script:

git clone git@github.com:Unleash/unleash.git
cd unleash
docker compose up -d

Then point your browser to localhost:4242 and log in using:

  • username: admin
  • password: unleash4all

If you'd rather run the source code in this repo directly via Node.js, see the step-by-step instructions to get up and running in the contributing guide.

2. Connect your SDK

Find your preferred SDK in our list of official SDKs and import it into your project. Follow the setup guides for your specific SDK.

If you use the docker compose file from the previous step, here's the configuration details you'll need to get going:

  • For front-end SDKs, use:
    • URL: http://localhost:4242/api/frontend/
    • clientKey: default:development.unleash-insecure-frontend-api-token
  • For server-side SDKs, use:
    • Unleash API URL: http://localhost:4242/api/
    • API token: default:development.unleash-insecure-api-token

If you use a different setup, your configuration details will most likely also be different.

Check a feature toggle

Checking the state of a feature toggle in your code is easy! The syntax will vary depending on your language, but all you need is a simple function call to check whether a toggle is available. Here's how it might look in Java:

if (unleash.isEnabled("AwesomeFeature")) {
  // do new, flashy thing
} else {
  // do old, boring stuff
}

Run Unleash on a service?

If you don't want to run Unleash locally, we also provide easy deployment setups for Heroku and Digital Ocean:

Deploy to Heroku Deploy to DigitalOcean

Configure and run Unleash anywhere

The above sections show you how to get up and running quickly and easily. When you're ready to start configuring and customizing Unleash for your own environment, check out the documentation for getting started with self-managed deployments, Unleash configuration options, or running Unleash locally via docker.


Online demo

Try out the Unleash online demo.

The Unleash online demo


Community and help — sharing is caring

We know that learning a new tool can be hard and time-consuming. We have a growing community that loves to help out. Please don't hesitate to reach out for help.

Join Unleash on Slack

💬 Join Unleash on Slack if you want ask open questions about Unleash, feature toggling or discuss these topics in general.

💻 Create a GitHub issue if you have found a bug or have ideas on how to improve Unleash.

📚 Visit the documentation for more in-depth descriptions, how-to guides, and more.


Contribute to Unleash

Building Unleash is a collaborative effort, and we owe a lot of gratitude to many smart and talented individuals. Building it together with community ensures that we build a product that solves real problems for real people. We'd love to have your help too: Please feel free to open issues or provide pull requests.

Check out the CONTRIBUTING.md file for contribution guidelines and the Unleash developer guide for tips on environment setup, running the tests, and running Unleash from source.

Contributors

The Unleash contributors


Features our users love

Flexibility and adaptability

Security and performance

  • Privacy by design (GDPR and Schrems II). End-user data never leaves your application.
  • Audit logs
  • Enforce OWASP's secure headers via the strict HTTPS-only mode
  • Flexible hosting options: host it on premise or in the cloud (any cloud)
  • Scale the Unleash Proxy independently of the Unleash server to support any number of front-end clients without overloading your Unleash instance

Looking for more features?

If you're looking for one of the following features, please take a look at our Pro and Enterprise plans:


Architecture

Read more in the system overview section of the Unleash documentation.


Unleash SDKs

To connect your application to Unleash you'll need to use a client SDK for your programming language.

Official server-side SDKs:

Official front-end SDKs:

The front-end SDKs connects via the Unleash Proxy in order to ensure privacy, scalability and security.

Community SDKs:

If none of the official SDKs fit your need, there's also a number of community-developed SDKs where you might find an implementation for your preferred language (such as Elixir, Dart, Clojure, and more).


Users of Unleash

Unleash is trusted by thousands of companies all over the world.

Proud Open-Source users: (send us a message if you want to add your logo here)

The Unleash logo encircled by logos for Finn.no, nav (the Norwegian Labour and Welfare Administration), Budgets, Otovo, and Amedia. The encircling logos are all connected to the Unleash logo.


Migration guides

Unleash has evolved significantly over the past few years, and we know how hard it can be to keep software up to date. If you're using the current major version, upgrading shouldn't be an issue. If you're on a previous major version, check out the Unleash migration guide!


Want to know more about Unleash?

Videos and podcasts

Articles and more