Git Product home page Git Product logo

posix-mq's People

Contributors

gitter-badger avatar jfether avatar mikeokner avatar mscdex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

posix-mq's Issues

Worker thread support

Hi! I'm trying to use this module in a worker thread but am hitting the following error:

FATAL ERROR: HandleScope::HandleScope Entering the V8 API without proper locking in place
 1: 0xb6dd00 node::Abort() [/usr/local/bin/node]
 2: 0xa7da28 node::FatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0xd471fa v8::Utils::ReportApiFailure(char const*, char const*) [/usr/local/bin/node]
 4: 0xd4875c v8::HandleScope::HandleScope(v8::Isolate*) [/usr/local/bin/node]
 5: 0xaac89c node::InternalCallbackScope::InternalCallbackScope(node::Environment*, v8::Local<v8::Object>, node::async_context const&, int) [/usr/local/bin/node]
 6: 0xaad0cf node::InternalMakeCallback(node::Environment*, v8::Local<v8::Object>, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context) [/usr/local/bin/node]
 7: 0xaad2e8 node::MakeCallback(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context) [/usr/local/bin/node]
 8: 0x7f7fb00c903e PosixMQ::poll_cb(uv_poll_s*, int, int) [/app/node_modules/posix-mq/build/Release/posixmq.node]
 9: 0x165e784  [/usr/local/bin/node]
10: 0x164c998 uv_run [/usr/local/bin/node]
11: 0xaad9e5 node::SpinEventLoop(node::Environment*) [/usr/local/bin/node]
12: 0xbb1c36 node::NodeMainInstance::Run() [/usr/local/bin/node]
13: 0xb29fe2 node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult*) [/usr/local/bin/node]
14: 0xb2d54d node::Start(int, char**) [/usr/local/bin/node]
15: 0x7f7fc9a7a083 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
16: 0xaaa1ce _start [/usr/local/bin/node]

Tested with Node v18 & v16.
The above stacktrace was from v18, but with v16 it's almost identical.

I did some surface research and saw some description of what would be needed to make this a 'context-aware addon' here: https://nodejs.org/api/addons.html#context-aware-addons

And additionally in the Nan repo this discussion led me to the NAN_MODULE_WORKER_ENABLED macro.

I'm going to try and pull the repo and see if I can make it work, but I'm a little bit in over my head with C++ and if significant changes are needed I'll probably not be able to do it :'D Any help / tips would be amazing!

Resolve deprecation warnings

Latest builds on Travis are throwing deprecation warnings:

$ npm install
> [email protected] install /home/travis/build/mikeokner/posix-mq
> node-gyp rebuild
make: Entering directory `/home/travis/build/mikeokner/posix-mq/build'
  CXX(target) Release/obj.target/posixmq/src/posixmq.o
In file included from ../src/posixmq.cc:19:0:
../node_modules/nan/nan.h: In constructor ‘Nan::Utf8String::Utf8String(v8::Local<v8::Value>)’:
../node_modules/nan/nan.h:1064:78: warning: ‘v8::Local<v8::String> v8::Value::ToString(v8::Isolate*) const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:2537): Use maybe version [-Wdeprecated-declarations]
       v8::Local<v8::String> string = from->ToString(v8::Isolate::GetCurrent());
                                                                              ^
../src/posixmq.cc: In static member function ‘static void PosixMQ::poll_cb(uv_poll_t*, int, int)’:
../src/posixmq.cc:113:75: warning: ‘v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*)’ is deprecated (declared at ../node_modules/nan/nan.h:958) [-Wdeprecated-declarations]
             Nan::MakeCallback(obj->handle(), emit, 1, read_emit_argv_local);
                                                                           ^
../src/posixmq.cc:130:76: warning: ‘v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*)’ is deprecated (declared at ../node_modules/nan/nan.h:958) [-Wdeprecated-declarations]
             Nan::MakeCallback(obj->handle(), emit, 1, write_emit_argv_local);
                                                                            ^
../src/posixmq.cc: In static member function ‘static void PosixMQ::Open(const Nan::FunctionCallbackInfo<v8::Value>&)’:
../src/posixmq.cc:185:58: warning: ‘v8::Local<v8::Object> v8::Value::ToObject() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:10254): Use maybe version [-Wdeprecated-declarations]
         v8::Local<v8::Object> config = info[0]->ToObject();
                                                          ^
../src/posixmq.cc:195:42: warning: ‘bool v8::Value::BooleanValue() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:2568): Use maybe version [-Wdeprecated-declarations]
             doCreate = val->BooleanValue();
                                          ^
../src/posixmq.cc:202:42: warning: ‘uint32_t v8::Value::Uint32Value() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:2571): Use maybe version [-Wdeprecated-declarations]
                 flags = val->Uint32Value();
                                          ^
../src/posixmq.cc:225:49: warning: ‘uint32_t v8::Value::Uint32Value() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:2571): Use maybe version [-Wdeprecated-declarations]
                 mode = (mode_t)val->Uint32Value();
                                                 ^
../src/posixmq.cc:239:55: warning: ‘bool v8::Value::BooleanValue() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:2568): Use maybe version [-Wdeprecated-declarations]
             if (val->IsBoolean() && val->BooleanValue() == true) {
                                                       ^
../src/posixmq.cc:246:59: warning: ‘uint32_t v8::Value::Uint32Value() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:2571): Use maybe version [-Wdeprecated-declarations]
                 obj->mqattrs.mq_maxmsg = val->Uint32Value();
                                                           ^
../src/posixmq.cc:254:60: warning: ‘uint32_t v8::Value::Uint32Value() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:2571): Use maybe version [-Wdeprecated-declarations]
                 obj->mqattrs.mq_msgsize = val->Uint32Value();
                                                            ^
../src/posixmq.cc: In static member function ‘static void PosixMQ::Send(const Nan::FunctionCallbackInfo<v8::Value>&)’:
../src/posixmq.cc:366:61: warning: ‘uint32_t v8::Value::Uint32Value() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:2571): Use maybe version [-Wdeprecated-declarations]
             if (info[1]->IsUint32() && info[1]->Uint32Value() < 32) {
                                                             ^
../src/posixmq.cc:367:49: warning: ‘uint32_t v8::Value::Uint32Value() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:2571): Use maybe version [-Wdeprecated-declarations]
                 priority = info[1]->Uint32Value();
                                                 ^
../src/posixmq.cc:377:85: warning: ‘v8::Local<v8::Object> v8::Value::ToObject() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:10254): Use maybe version [-Wdeprecated-declarations]
             send_result = mq_send(obj->mqueue, node::Buffer::Data(info[0]->ToObject()),
                                                                                     ^
../src/posixmq.cc:378:56: warning: ‘v8::Local<v8::Object> v8::Value::ToObject() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:10254): Use maybe version [-Wdeprecated-declarations]
                 node::Buffer::Length(info[0]->ToObject()), priority);
                                                        ^
../src/posixmq.cc: In static member function ‘static void PosixMQ::Receive(const Nan::FunctionCallbackInfo<v8::Value>&)’:
../src/posixmq.cc:424:46: warning: ‘bool v8::Value::BooleanValue() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:2568): Use maybe version [-Wdeprecated-declarations]
             retTuple = info[1]->BooleanValue();
                                              ^
../src/posixmq.cc:427:55: warning: ‘v8::Local<v8::Object> v8::Value::ToObject() const’ is deprecated (declared at /home/travis/.node-gyp/11.6.0/include/node/v8.h:10254): Use maybe version [-Wdeprecated-declarations]
         v8::Local<v8::Object> buf = info[0]->ToObject();
                                                       ^
  SOLINK_MODULE(target) Release/obj.target/posixmq.node
  COPY Release/posixmq.node
make: Leaving directory `/home/travis/build/mikeokner/posix-mq/build'
added 1 package from 8 contributors and audited 1 package in 2.912s
found 0 vulnerabilities
The command "npm install" exited with 0.
0.08s$ node test.js
Writing 100 ('d') to the queue...
Writing 98 ('b') to the queue...
Writing 56 ('8') to the queue...
Writing 40 ('(') to the queue...
Writing 62 ('>') to the queue...
Writing 108 ('l') to the queue...
Writing 41 (')') to the queue...
Writing 83 ('S') to the queue...
Writing 41 (')') to the queue...
Writing 125 ('}') to the queue...
Writing 70 ('F') to the queue...
(node:5840) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
Received message (1 bytes): d
Messages left: 9
Received message (1 bytes): b
Messages left: 8
Received message (1 bytes): 8
Messages left: 7
Received message (1 bytes): (
Messages left: 6
Received message (1 bytes): >
Messages left: 5
Received message (1 bytes): l
Messages left: 4
Received message (1 bytes): )
Messages left: 3
Received message (1 bytes): S
Messages left: 2
Received message (1 bytes): )
Messages left: 1
Received message (1 bytes): }
Messages left: 0
The command "node test.js" exited with 0.

Hopefully possible to resolve while still maintaining full backwards compatibility. If not we can drop support for versions of Node that are no longer supported.

Keep listening for messages

When running the following code the node script exits after all available messages have been read. Is this behaviour intended? I would like it to keep listening for new messages.

var mq = new PosixMQ();
var readbuf = new Buffer(mq.msgsize);
mq.on('messages', function() {
    var n;
    while ((n = this.shift(readbuf)) !== false) {
        console.log("Received message ("+ n +" bytes): "+ readbuf.toString('utf8', 0, n));
        console.log("Messages left: "+ this.curmsgs);
    }
});
mq.open({name: '/pmqtest'});

Existing messages in a queue causes a script to exist unexpectedly after processing

If starting a script to read a queue and there are already messages in the queue, then the script will process the existing messages and then unexpectedly exit. If there are no messages in the queue when the script starts, then the script will run indefinitely and process new messages as desired.

Reproducing the issue:

Consumer:

var PosixMQ = require('posix-mq');
var readChannel = new PosixMQ();


readChannel.on('messages', function() {
  var n;

  while ((n = this.shift(readbuf)) !== false) {
    var msg = readbuf.toString('utf8', 0, n);
    console.log('fromSensor: ' + msg)
  }

});

readChannel.open({
  name: '/fromSensor',
  create: true,
  mode: '0777',
  maxmsgs: 10,
  msgsize: 256
});

readbuf = new Buffer(readChannel.msgsize);
console.log('Readchannel opened');
console.log('--------------------------------------');

Producer:

var PosixMQ = require('posix-mq');   
var keypress = require('keypress');

var writechannel = new PosixMQ();

writechannel.open({
  name: '/fromSensor',
  create: true,
  mode: '0777',
  maxmsgs: 10,
  msgsize: 256
});


console.log('writechannel opened');
console.log('--------------------------------------');


keypress(process.stdin);
process.stdin.on('keypress', function (ch, key) {

 switch(ch) {
   case 'q':
   process.exit()
   break;

   case 'w':
    var msg = 'test-write';
    writechannel.push(msg);
    console.log('Send');
   break;
 }
});

process.stdin.setRawMode(true);
process.stdin.resume();

Work-around for now is to read existing messages before assigning event handler.

Error: Message too long

I am getting an error that my mqueue message is too long. Seems like my msgsize parameter isn't working in mq.open()

Here's the code that I'm using:

const PosixMQ = require('posix-mq');
var mq = new PosixMQ();

app.post('/', function(req, res){
	mq.open({
		name: '/testing',
		create: true,
		mode: 0777,
		maxmsgs: 10,
		msgsize: 256 
	});
       
        var str = JSON.stringify(req.body.data);

	console.log("Max size is: " + mq.msgsize);
        //Prints '8' regardless of value of msgsize above

	console.log("Writing " +  str + " to the queue..");
        // Prints 'Writing helloworld to the queue' 

	mq.push(str); //Error: Message too long
       
	
	mq.close();
});

Any help is appreciated.

Node version: 10.15.4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.