Node.js process.exit () does not fail, but the dangers of async fs.writeFile

TL; dr:

Calling asynchronous fs.writeFilefrom asynchronous events (and, possibly, even from a simple old loop), and then calling process.exit()successfully opens files, but does not allow you to clear data in files. The callbacks transferred writeFiledo not have the ability to run before the process exits. Is this expected behavior?

Regardless of whether process.exit()this cleanup does , I questioned whether it should be the duty of the node to at least try to write the file to the schedule, because it may well be that freeing up huge buffers depends on writing to the disk.

more details

I have a conceptually basic piece of node.js code that does the conversion in a large data file. This is a LiDAR sensor data file that should not be relevant. This is just a data set that is large enough due to the nature of its existence. It is structurally simple. The sensor transmits its data over the network. My task for this script is to create a separate file for each rotating scan. The details of this logic are also irrelevant.

The basic idea is that I am using node_pcap to read a huge file .pcapusing the method given for this task using node_pcap, which is "offline mode".

, , , , , "".

, pcap. , pcap. packet .

. , , . fs.writeFile(), . , , node , .

, fs.writeFileSync fs.writeFile OS write() . , , , , , . , writeFileSync node , syscall write().

, writeFile (js- ), , . . - , .

. , node , , . . , - RAM. , , , . , node , , ...

, process.exit(), , node writeFile .

node .

writeFileSync . , process.exit() , , ( , writeFile ) , .

, -, , process.exit().

: ? . , process.exit() , .

node v0.10.26, OS X Homebrew.

, , , writeFile. , , node , . , -, node , "" .

, . outbox , , . , , , , - , , . , , node , - , . , , outbox, RAM. , . , .

, , , , , , writeFileSync, , node.

, writeFile? , ( - ) ( IaaS , - ), ?

, , , , . , , - . , , node "" .

+4
1

node, , , . , . 9 Professional NodeJS . - . , .

0

Source: https://habr.com/ru/post/1546251/


All Articles