Cannot read a file that is used by another process

I am trying to read a file with the Overwolf API (overwolf.io.readFileContents), but the file I am trying to read is always opened by another process. I know that you can open such files because with the normal Node fs module you can open it regularly, but the Overwolf API doesn’t let you.

Here is the code snippet in question:

const data: string = await new Promise((resolve, reject) => {
    overwolf.io.readFileContents(
        lockfilePath,
        overwolf.io.enums.eEncoding.UTF8,
        ({ error, content }) => {
            if (error) reject(error);
            resolve(content!);
        }
    );
});

Hi!
This does in fact seem like a weird interaction. I’ll check this internally and see if it’s a known phenomena or not, and also what you should do about it.

So!
While we’re looking into it, we have a few questions:
What’s the name (or rough purpose) of the file in question?
Why is it constantly open (is it something like a log file that’s constantly being written to)?

The file is the lockfile of the game that stores the keys to use the internal api of the game. I contacted support of the game and i got permission to use the api, if it not alters the gameplay of the person using the program (for example ESP is bannable because is gives an unfair advantage, but something like a stats tracker which I am trying to make is allowed)

Interesting.
So, for debugging purposes, could you please try the following methods, to see if any of them works?
file stream
read by type (text/binary)
copy to then read from the copy

overwolf.io.listenOnFile and overwolf.io.copyFile didn’t work, but overwolf.io.readTextFile and overwolf.io.readBinaryFile did work. Thank you very much for the help.

Glad to hear that worked!
This still does sound like an issue though, so it would help us if you could share some details so we can try to figure out what went wrong (depending on what you want to/can share):
Does this still happen even when the game is closed?
Can you provide the original file/a file where the issue also occurs?
What game is it happening in?

The file in question is the lockfile of Valorant. The Game always reads and writes the file to use internal APIs. If I close the game, the file does not exist. It seems like overwolf.io.readTextFile() can read files that are being read by other processes, but overwolf.io.readFileContents() cannot. Unfortunately, I cannot provide the file because it may contain keys that could be used maliciously by others.

Interesting.
So, in general, readTextFile and readBinaryFile are more stable (and also faster!), so it’s not too bad, but we’ll look into it to find out the exact circumstances (and at least add a warning if it isn’t a bug)

Thank you once again for the details, and let us know if you encounter anything else!