Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logs command shows extra one-character line #338

Closed
dandv opened this issue Mar 7, 2014 · 2 comments
Closed

logs command shows extra one-character line #338

dandv opened this issue Mar 7, 2014 · 2 comments

Comments

@dandv
Copy link
Contributor

dandv commented Mar 7, 2014

I have an app that outputs lots of messages in verbose mode, about 3-5 lines per second. pm2 logs shows the log scrolling, but sometimes one line is show before the real log line, containing only the first character of the real log line:

[myapp-prod-2 (out) 2014-03-07T07:06:59] Got record "Cbe6PFbHX84ehSPQ9"
[myapp-prod-2 (out) 2014-03-07T07:06:59] Inserted
[myapp-prod-2 (out) 2014-03-07T07:06:59] G
[myapp-prod-2 (out) 2014-03-07T07:06:59] Got record "wLtnSrxnLRqnCA6PK"
@matthijskooijman
Copy link

I'm seeing this as well. It seems that the info is correctly written to the logfile itself and when pm2 logs shows pre-existing log entries at startup, those are also correctly shown.

Looking at the code, I suspect that the problem is here: https://github.com/Unitech/pm2/blob/master/lib/Log.js#L46

The "start" and "end" parameters are both inclusive. This means that if you pass the size of a file to "end", it will try to read one past the end. Normally, reading just stops at EOF, but when writing happens after the stat, but before EOF is reached, this reads one extra byte of data.

Changing the end parameter to prevSize -1 prevents that, but also exposes another problem: https://github.com/Unitech/pm2/blob/master/lib/Log.js#L41 This line should really be >= instead of >.

With both changes applied, I haven't seen the problem occur again so far. I'm not sure if this is a complete solution though - my gut feeling says there is still a race condition hidding somewhere (at the very least it is possible for a single log line to be spread over two lines of output).

@soyuka
Copy link
Collaborator

soyuka commented Jun 12, 2014

Nice! Would you be able to make a Pull-Request on that?

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

No branches or pull requests

4 participants