Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Node.js module initialization issue when starting module is .NET #96

Closed
teamdevmatch opened this issue Jan 12, 2017 · 7 comments
Closed
Assignees

Comments

@teamdevmatch
Copy link

Hey guys,

first of all I want to thank everybody who is contributing to this repo. I really think you're doing an amazing job here providing us with this open foundation for creating custom hybrid solutions in a fast and consistent way. Also looking forward to be a contributor very soon.

Right now I'm messing around with various gateway configurations and ran into an issue when setting up a Node.js module as sink and a starting .NET module as source.

When I start up the gateway it outputs the following message: Info: Module has not been initialized yet: State: 1, Module: ../../../../samples/nodejs_simple_sample/nodejs_modules/filewriter.js

Then the gateway prints: Gateway is running. and the .NET source module starts sending messages to the broker correctly.

The first message is not being processed by the Node module.
Oddly enough, after ignoring the first message, the Node.js module starts processing incoming messages just fine.

I'm guessing the very first message kind of initializes the Node module and after that the module works as expected.

My question:
Is there anything that I'm missing in the configuration to instruct the gateway to initialize all modules on start? Am I doing something else wrong here or this an actual issue?

As a workaround I'm thinking about sending an initial wake-up / warm-up message, so that Node modules are initializing.

Thanks for reading all of that and y'all have a good one.

@avranju
Copy link
Contributor

avranju commented Jan 12, 2017

Thanks for filing the issue @teamdevmatch. From what I can tell it sounds like a race condition of sorts. The .NET module appears to get initialized and starts producing messages before the Node.js module has had a chance to load and initialize. Are you commencing sending of messages from your .NET module from the IGatewayModule.Create method or are you using the IGatewayModuleStart.Start method as a signal for triggering the start of message production?

@teamdevmatch
Copy link
Author

Hey @avranju, the .NET module is the SDK's sensor sample (DotNetSensorModule) and the thread for publishing messages is created in the IGatewayModuleStart.Start method. This should be the right place, I reckon.
Going to fiddle around a bit on replacing the Thread with a Timer or Task but I not sure if that'll make any difference.
Thanks so far looking into this topic.

@avranju
Copy link
Contributor

avranju commented Jan 13, 2017

I see. I am going to say that this is an issue with the Node.js binding implementation. In this case I would expect the binding code that bridges the Node.js runtime with the rest of the gateway to delay delivery of the message to the JS code till it has been initialized. I'll file a task for this and get this addressed. Thanks for reporting this!

@teamdevmatch
Copy link
Author

Alright, that seems reasonable. Just found out when I give the message thread a little Thread.Sleep(500) before creating the first message the Node module will initialize without any warning/info and also process the first message.

@damonbarry
Copy link
Member

@teamdevmatch Update: @zafields is working on this fix for this...shouldn't take too much longer.

@zafields
Copy link
Contributor

@teamdevmatch The fix is in master, can you please update and confirm this addresses your issue.

@teamdevmatch
Copy link
Author

Hey @zafields,

sorry for the delayed answer, i had some issues updating and building the new sources...
... after i did a new clone, the build succeeded and i can confirm that my issue is resolved and now the gateway works as expected.

Thanks for the fix, i am closing this issue...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants