3

I'm working with a temp file that's downloaded from a server. but when I ran it on macOS, it ran fine. and did what it was supposed to do. but when I ran it on windows, it keeps giving me an EBUSY error when trying to spawn the child. I tried delaying the start of the file. tried to remove the chmod so it just runs on Linux and macOS. But still getting the Ebusy error. Am I doing something wrong?

Note: I can launch the binary from another node instance outside. Like from a cmd. but launching it from the node instances that created it leads to a Ebusy error.

temp.open('', (err, info) => {
      if (err) throw err;
      console.log('File: ', info.path);
      console.log('Filedescriptor: ', info.fd);
      var data = fs.createWriteStream(info.path);
      res.data.pipe(data);
      data.on('close', async () => {
        fs.chmodSync(info.path, 0o755);
        await delay(1000);
        var child = cp.spawn(info.path, [key, jwt], { stdio: ['inherit', 'inherit', 'inherit', 'ipc'] });

Error:

Error: spawn EBUSY
    at ChildProcess.spawn (node:internal/child_process:415:11)
    at Object.spawn (node:child_process:707:9)
    at WriteStream.<anonymous> 
    at WriteStream.emit (node:events:394:28)
    at emitCloseNT (node:internal/streams/destroy:138:10)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4082,
  code: 'EBUSY',
  syscall:

Edit: I created a new module to try to spawn the child that way. it will be forked in the main process. but I'm still getting the same error in the fork. still the same error.

const cp = require('child_process')

const childpath = process.argv[2]

var argv = [];
for (let index = 3; index < process.argv.length; index++) {
    const element = process.argv[index];
    argv.push(element)
}
console.log(argv)
var child = cp.spawn(childpath, argv, {
    stdio: ['inherit', 'inherit', 'inherit', 'ipc']
})
child.on('message', (msg) => {
    if (process.send) process.send(msg)
    else process.emit('message', msg)
})
child.on('error', (msg) => {
    console.log(msg)
    process.emit('error', msg)
})
child.on('close', (msg) => {
    process.exit(msg)
})

Update: I've noticed that I cannot run the file until the process the created it is ended. meaning that the process that needs to use it is using it. but I cannot do the thing I want to do with it.EI spawn it The Error

Update 2: The next thing I tried was to create a symbolic link with the node. And still nothing but I noticed that the file doesn't become runnable until the main process is ended. which means that the process that I'm running has something to do with it. So I need to be able to unlike it from the process that's running. it seems like windows need to do some initialization after the file is made. and because it's still connected to the main process in some way it's not able to. Im guess this is why when I ended the process, the node icon showed up on the symlink and that's why I'm able to run it manually.

Final Update: I'm gonna work on a file system module that acts like temp files but is just regular files. that the process is tracking. giving the function of temp files but not really. this will allow me to use the function of temp files but without the file being unable to be executed. It seems like making it a temp file made it so it could not be executed by the same process that created it. it seems like a windows file system thing and how they handle temp file permissions.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Mo K
  • 45
  • 6

1 Answers1

0

The way Temp files are handled in windows is different than macOS. to my best estimate, it seems like Temp files in windows are linked to the process that created them and aren't able to be changed or accessed by that process. The problem lies in trying to execute these temp files which windows has assigned to a process already making it unassignable. NodeJs needs to be able to access the file to be able to launch it and windows permission will not allow it until the main process is killed or ended. this unlinks the file from that process making it accessible to the rest of the system.

Mo K
  • 45
  • 6