buckyos/CYFS

Start DEC APP failed,The DEC APP log file is empty

Closed this issue · 2 comments

Describe the bug
Start DEC APP failed,The DEC APP log file is empty
test DEC APP 1.0.4 : cyfs://5r4MYfFJ7ktzBzSi1sWmU7BJLgpEEdp8ukbWemsFuQc1/9tGpLNnH1nXE3Ku2CgrQuc3JggtJuvAM3sP3Ype33qSv

To Reproduce

  • When I installed the DEC APP in the CYFS browser, I found that the DEC APP failed to start 6 times repeatedly, and the written log file was empty
  • I run sudo node service.js --start directly on the server, the operation is normal, and the log file is normal

Expected behavior
Why the log file of DEC APP is empty and needs to be checked

OOD System :Linux VPS OOD , Without root user

test_log_error.zip

I have looked at your service code: ``javascript

let save_path = path.join(__dirname, "test_read.txt")
fs.writeFileSync(save_path, "test file").
fs.chmodSync(save_path, 0o400).

This code will throw an exception inside docker because the app service's directory will be mounted as read-only when it starts
Logging may be lost when an exception is thrown.

This depends on the implementation of the logging library you are using.

you can use try catch to catch the exception from code and try to write it into log file

This is generally related to the specific logging system and corresponding configuration used by the DEC app. In most cases, an asynchronous logging system is used. If a panic occurs after starting, the logs might not have been flushed to disk yet. Based on previous development experiences, there are a few suggestions for improvement:

1. Switch to a synchronous logging system

The advantage is that some critical logs won't be lost, but the downside is that it may significantly affect performance when the log volume is large.

2. Use the flush method of the logging system

When outputting some critical logs, force the flush to write all pending logs to disk. For example, after a panic/exception occurs, you can synchronously call log.flush in the on_cache function.