
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
fair-semaphore
Advanced tools
A semaphore that unlocks waiters in a fair manner, by key, to allow balancing between different consumers
With this module, you can block work from multiple incoming sources and the work will be unblocked in a fair order. One source cannot cause starvation of the other sources.
A fair queue could be used to schedule incoming requests from users, to make sure that no user reduces the performance of other users on the same server. Or, the queue could be used to balance outgoing requests to a downstream server, making sure that one user does not consume all of the connections in a pool.
In this example, source 1 will request two items of work before source 2 can try to request anything. But, when the work is unblocked, the work from source 2 will be unlocked first so that source 1 does not starve source 2.
const FairSemaphore = require('fair-semaphore');
const semaphore = new FairSemaphore();
semaphore.take('source1', function () {
console.log('Inside first request from source 1');
semaphore.leave();
});
semaphore.take('source1', function () {
console.log('Inside second request from source 1');
semaphore.leave();
});
semaphore.take('source2', function () {
console.log('Inside first request from source 2');
semaphore.leave();
});
When the above code is executed, the output will be
Inside first request from source 1
Inside first request from source 2
Inside second request from source 1
Notice that the request for source 2 was allowed before the second request from source 1, so that source 1's double requests did not starve source 2.
FAQs
A semaphore that unlocks waiters in a fair manner, by key, to allow balancing between different consumers
The npm package fair-semaphore receives a total of 0 weekly downloads. As such, fair-semaphore popularity was classified as not popular.
We found that fair-semaphore demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.