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

fileAppender write after end, #385

Closed
leegee opened this issue May 4, 2016 · 5 comments
Closed

fileAppender write after end, #385

leegee opened this issue May 4, 2016 · 5 comments

Comments

@leegee
Copy link

leegee commented May 4, 2016

Log4js-node: "version": "0.6.35"

package.json.txt

Circumstance: with a large log file, or any empty log file.

Configuration:

{
    "appenders": [
        {
            "type": "categoryFilter",
            "exclude": [],
            "appender": {
                "type": "console",
                "layout": {
                    "type": "pattern",
                    "pattern": "%[%-10c %-5p%] %m"
                }
            }
        },
        {
          "type": "file",
          "filename": "temp.log",
          "maxLogSize": 20480,
          "layout": {
             "type": "pattern",
             "pattern": "%[%-10c %-5p%] %m"
          }
        }
    ],
    "replaceConsole": true
}

Output (repeated many, many times):

�[31mconsole    ERROR�[39m log4js.fileAppender - Writing to file temp.log, error happened  [Error: write after end]
Error: write after end
    at writeAfterEnd (_stream_writable.js:159:12)
    at RollingFileStream.Writable.write (_stream_writable.js:204:5)
    at Logger.<anonymous> (D:\src\thin-monitor2\node_modules\log4js\lib\appenders\file.js:68:13)
    at emitOne (events.js:82:20)
    at Logger.emit (events.js:169:7)
    at Logger._log (D:\src\thin-monitor2\node_modules\log4js\lib\logger.js:91:8)
    at Logger.(anonymous function) [as info] (D:\src\thin-monitor2\node_modules\log4js\lib\logger.js:83:14)
    at Console.log (D:\src\thin-monitor2\node_modules\log4js\lib\log4js.js:359:10)
    at Object.puts (C:\Users\lee\AppData\Roaming\npm\node_modules\protractor\built\logger.js:24:17)
    at log_ (C:\Users\lee\AppData\Roaming\npm\node_modules\protractor\built\launcher.js:24:12)

Followed by:

RangeError: Maximum call stack size exceeded
    at Function.getOwnPropertyNames (native)
    at cloneCallSite (C:\Users\lee\AppData\Roaming\npm\node_modules\protractor\node_modules\source-map-support\source-map-support.js:301:10)
    at wrapCallSite (C:\Users\lee\AppData\Roaming\npm\node_modules\protractor\node_modules\source-map-support\source-map-support.js:328:13)
    at C:\Users\lee\AppData\Roaming\npm\node_modules\protractor\node_modules\source-map-support\source-map-support.js:358:26
    at Array.map (native)
    at Function.prepareStackTrace (C:\Users\lee\AppData\Roaming\npm\node_modules\protractor\node_modules\source-map-support\source-map-support.js:357:24)
    at D:\src\thin-monitor2\node_modules\log4js\lib\layouts.js:30:40
    at Array.map (native)
    at wrapErrorsWithInspect (D:\src\thin-monitor2\node_modules\log4js\lib\layouts.js:29:16)
    at formatLogData (D:\src\thin-monitor2\node_modules\log4js\lib\layouts.js:40:34)
@stanleyxu2005
Copy link

stanleyxu2005 commented Jan 11, 2017

use fileSync appender instead. maybe there is some performance downgrade, but this is my default choice.

@mgendre
Copy link

mgendre commented Feb 20, 2017

We also have the same problem when our server ends with an uncaught exception.
This problem is present with the version 1.1.0.

Our code looks like:

function exitFailure(error) {
	...
    log4js.shutdown(function() { process.exit(1); });
}

process.on('uncaughtException', function(error) {
    exitFailure(new Error('Uncaught exception'));
});

With the 1.1.0, the logs are not written and the error "write after end" is written in the console.

We use a file appender. For performance, we don't want to use fileSync appender.

With the release 1.0.1, the problem disappear and the logs are written in the files.

Any suggestions or incoming bugfix ?

@stanleyxu2005
Copy link

@leegee I previously had same issue, but i realized I didn't shutdown my app properly, which is the root cause. You might check, whether your app can shutdown before process.on('exit') is called.

@nomiddlename
Copy link
Collaborator

A few causes of the "write after end" problem were fixed in version 2.x. Please re-open if they are still occurring.

@DJMit-alt
Copy link

shutdown have still issues. kindly see #788

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

No branches or pull requests

5 participants