
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
BSW is a Node.js framework for beanstalkd workers
Table of Contents
Node.js v10 or above is required.
Updated dependencies and dropped node 8 support.
Consumer
const {Consumer} = require('bsw');
(async () => {
const consumer = new Consumer({
host: '127.0.0.1',
port: 27017,
tube: 'example',
handler: async function (payload, job_info) {
console.log('processing job: ', payload);
return 'success';
}
});
// handling errors
consumer.on('error', (e) => {
console.log('error:', e);
});
await consumer.start();
})();
Producer
const {Producer} = require('bsw');
(async () => {
const producer = new Producer({
host: '127.0.0.1',
port: 27017,
tube: 'example'
});
// handling errors
consumer.on('error', (e) => {
console.log('error:', e);
});
await producer.start();
await producer.putJob({
payload: JSON.stringify({throw: true, result: 'success'}),
priority: 0,
delay: 0,
ttr: 60
});
producer.stop();
})();
In v2, handler must be an async function(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)
handler
interface:
async handler(payload, job_info)
handler
definition examples:
async handler(payload, job_info) {
console.log('Hello world!');
}
After job reservation, handler
would be called. Each job must get one of the following status after processing:
To report the job status, it must be returned or thrown from handler function:
// delete job
return 'success';
throw 'success';
// bury job
return 'bury';
throw 'bury';
// reput job without delay
return 'release';
throw 'release';
// reput job with 10s delay
return ['release', 10];
throw ['release', 10];
Default statuses:
handler
returned with unknown keywordhandler
thrown with unknown keywordFor example:
async handler(payload, job_info) {
try {
await mayThrow();
} catch (e) {
return 'bury'
}
return 'success';
}
equals to
async handler(payload, job_info) {
await mayThrow();
}
You may add an optional post processing of jobs, to do this add final
function to the handler with the following interface:
NOTE: post processing apply after job status was sent to beanstalkd
async final(status, delay, result)
success
, release
or bury
)release
or null
handler
BSW Consumer class is used to connect to beanstalkd server and subscribe to a tube
The Consumer constructor takes configuration object:
'127.0.0.1'
)11300
)'default'
)false
)30
)1
)close
event (default value false
)async start()
functionStart the worker.
await
key word.consumer.start()
directly, it will return immediately and process the actual start action asynchonouslyawait consumer.start()
inside an async function, it will wait until the start process finishes and then process the code at the backExample:
const consumer = new Consumer({
host: '127.0.0.1',
port: 27017,
tube: 'example',
handler: async function (payload, job_info) {
console.log('processing job: ', payload);
return 'success';
}
});
// could be called directly without await
consumer.start();
// this line will be immediately called because start() is async function
console.log('do something');
// or could be called inside async function context
(async () => {
await consumer.start();
// this line will be called after start() returns
console.log('do something');
})();
stop()
functionStop the consumer immediately, and any processing jobs won't report to beanstalk. Example
consumer.stop();
async stopGracefully(timeout)
functionStop the consumer in a more graceful way. Will wait until all the processing jobs are done and reported to beanstalk, or wait for a user-specific timeout value.
Example
// stop the consumer gracefully within 3s
await consumer.stopGracefully(3000);
BSW Producer class is used to connect to beanstalkd server and put jobs to a tube
The Producer constructor takes configuration object:
'127.0.0.1'
)11300
)'default'
)false
)async start()
functionSame as Consumer class.
stop()
functionSame as Consumer class.
async putJob(job)
functionPut jobs to the tube. Receives an job
object which has the following attributes:
Example:
await producer.putJob({
payload: JSON.stringify({key: 'value'}),
priority: 0,
delay: 0,
ttr: 60
});
Find the full example in example
directory:
To run, clone the project, then:
> npm install
(If you have `yarn` installed in your machine, we recommand you use `yarn install` instead)
> cd example
> node producer.js
> node consumer.js
FAQs
Beanstalkd worker framework for co/Promise based handlers
The npm package bsw receives a total of 14 weekly downloads. As such, bsw popularity was classified as not popular.
We found that bsw 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
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.