Comments (14)
When I run npm test
in the good-console directory, I do not see this error on both version 0.10.40 and version 4.0.0 of Node. What version are you using? Also, that's a pretty hefty stack and it doesn't look like you are testing good-console directly.
from good-console.
I am on node 4.2.2 and using those dependencies:
"good": "~6.4.0",
"good-console": "^5.2.0",
No my tests are not testing good console, they just start my hapi app 11x times and then shut it down again.
from good-console.
Yeah are you using wreck and listening for wreck events? That is generally where that error comes from. Since wreck is a singleton, every test attaches another event listener to the singleton and is never cleaned up.
https://github.com/hapijs/good/blob/master/test/index.js#L11-L12
from good-console.
I am not using Wreck directly, I am using h2o2 and other modules, so I can't even directly require wreck to set MaxListeners on it.
from good-console.
Good attaches a listener to wreck so if you are creating your server over and over in your tests, that's what is going to cause it. Without seeing anything else, that is the best I can do.
I'm going to close this issue as good-console doesn't even have a reference to wreck and the problem is not originating from this module. If you need additional help, open an issue at https://github.com/hapijs/discuss/issues.
from good-console.
I am not 100% sure if this issue is actually related to wreck. I was able to get rid of the warning by changing the the GoodConsole.init function:
internals.GoodConsole.prototype.init = function (stream, emitter, callback) {
var self = this;
if (!stream._readableState.objectMode) {
return callback(new Error('stream must be in object mode'));
}
var filter = this._filter;
var transform = Through.obj(function goodConsoleTransform (data, enc, next) {
var eventName = data.event;
var tags = [];
/*eslint-disable */
if (Array.isArray(data.tags)) {
tags = data.tags.concat([]);
} else if (data.tags != null) {
tags = [data.tags];
}
/*eslint-enable */
tags.unshift(eventName);
if (eventName === 'response') {
this.push(self._formatResponse(data, tags));
return next();
}
if (eventName === 'wreck') {
this.push(self._formatWreck(data, tags));
return next();
}
var eventPrintData = {
timestamp: data.timestamp || Date.now(),
tags: tags,
data: undefined
};
if (eventName === 'ops') {
eventPrintData.data = Hoek.format('memory: %sMb, uptime (seconds): %s, load: %s',
Math.round(data.proc.mem.rss / (1024 * 1024)),
data.proc.uptime,
data.os.load);
this.push(self._printEvent(eventPrintData));
return next();
}
if (eventName === 'error') {
eventPrintData.data = 'message: ' + data.error.message + ' stack: ' + data.error.stack;
this.push(self._printEvent(eventPrintData));
return next();
}
if (eventName === 'request' || eventName === 'log') {
eventPrintData.data = 'data: ' + (typeof data.data === 'object' ? SafeStringify(data.data) : data.data);
this.push(self._printEvent(eventPrintData));
return next();
}
// Event that is unknown to good-console, try a defualt.
if (data.data) {
eventPrintData.data = 'data: ' + (typeof data.data === 'object' ? SafeStringify(data.data) : data.data);
}
else {
eventPrintData.data = 'data: (none)';
}
this.push(self._printEvent(eventPrintData));
return next();
})
var first = stream.pipe(filter);
var second = first.pipe(transform);
var last = second.pipe(process.stdout);
emitter.on('stop', function(){
stream.emit('close');
first.emit('close');
second.emit('close');
last.emit('close');
})
callback();
};
Not sure if this is a good approach, if so I would create a PR.
from good-console.
What did you change? That is a lot of code.
from good-console.
the MAIN change is adding these:
emitter.on('stop', function(){
stream.emit('close');
first.emit('close');
second.emit('close');
last.emit('close');
})
rest is smaller refactoring, I could try to only emit a close event on the last stream, maybe its sufficient. Ill create a PR, in order to make comparison easier.
from good-console.
Again; when I run the tests on just good-console, I don't have this issue.
Also, you shouldn't be emitting anything on stream
because that object is being passed around to a bunch of other reporters and you have no idea what the downstream impact is of emitting a "close" event on a stream that is being consumed by multiple other streams.
If you can create an example using ONLY good-console that shows this error, then we can look at trying to make it go away. At present, I am not convinced that the issue is in good-console.
I also don't think you are supposed to manually emit a "close" event as the stream should emit that when it is actually closed, like when null
is pushed through. Like here - https://github.com/hapijs/good-console/blob/master/test/index.js#L526
from good-console.
I have now done the minimal necessary change to get rid of this error in #58.
My Testcase for it was just starting my server 11 times.
So any example app with good console should be able to reproduce this issue, unfortunately the good-console testcases, are not embedded within hapi, so its not that easy to show that behaviour.
from good-console.
There isn't an error though. The error is coming from your hapi server setup. If you open good-console
and run npm test
, this message is not printed.
As I said earlier, it's the registration of good - https://github.com/hapijs/good/blob/master/lib/monitor.js#L186 that line happens 11 times and adds 11 listeners to the wreck instance.
from good-console.
I have created a sample app that reproduces the error: https://github.com/KeKs0r/hapi-good
node_modules/lab/bin/lab test.js
You could replace the good console with my version in order to show that the error is gone afterwards
from good-console.
I pulled your code and fiddled with it. The problem is that when good is stopped (https://github.com/hapijs/good/blob/master/lib/monitor.js#L201) it does push null
through the _dataStream
readable stream. When I make that change to the local install of Good, the tests pass fine without the warning. The issue was on piping to process.stdout
as that is ALSO a singleton (like Wreck).
While this obviously isn't correct for Good to not tear down these streams properly, I'm hesitant to make this change in Good because it may have many downstream impacts on the existing reporter ecosystem. That being said, there is a version 7 branch of good, and I'll be sure to add this change there.
from good-console.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
from good-console.
Related Issues (20)
- responseSentTime is undefined HOT 7
- post/patch body params? HOT 2
- New Lead Maintainer Requested HOT 1
- Log remoteAddress and X-Forwarded-For HOT 3
- Require node v8 HOT 1
- Change module namespace HOT 1
- Action required: Greenkeeper could not be activated 🚨 HOT 1
- Update deps HOT 1
- Update joi HOT 1
- Only node 12
- documentation request: consider adding to the #usage section an explicit example of integrating with Hapi server <eom> HOT 1
- request.log tagged as error HOT 3
- I just want to print the good console logs with time, please find the below code which i am using HOT 3
- Ignore log of specific routes HOT 5
- How should I use the [config] - optional configuration object? HOT 3
- wreck events are not formatted correctly in console logging HOT 2
- Example good integration for transforming events into strings HOT 4
- Log the events in a response tail? HOT 2
- Allow to choose between `responseTime` and `responseSentTime` HOT 3
- Moment Security Advisory HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from good-console.