Race condition with fs.mkdirSync
when multiple processes create a client with logging turned on at the same time
#141
Labels
Description
in
src/OAuthClient.js#OAuthClient
we have the following section of code (https://github.com/intuit/oauth-jsclient/blob/master/src/OAuthClient.js#L61):If multiple processes are started on a machine that has no .logs folder created and this section of code is executed, it is feasible that the following timeline happens:
Example error I encountered in a Github CI Actions environment, in a setup where there is a main API process and one worker process for heavy tasks. Both of them encounter the code where they create such a client. The CI run fails for me since the backend is not successfully created due to the error thrown when the worker tries to create a client, in a fashion similar to the one described above. The following error is thrown:
To reproduce
Due to the nature of the issue, it can be hard to reproduce, and in the CI environment I ran, it happens rarely, but it does happen.
If multiple processes are started and create the client like
For easier time reproducing this issue, use a bash script that removes the .logs folder and then starts multiple of these processes in parallel
Proposed fix
Not sure what the best practice in this case would be, but something like wrapping the
mkdirSync
function call and ignoring theEEXIST
error code works for me (and is what I do currently in my case to solve the issue for myself), as shown here: https://riptutorial.com/node-js/example/5638/avoiding-race-conditions-when-creating-or-using-an-existing-directoryNot sure if that is hacky or has other downfalls, so am open to a better solution
The text was updated successfully, but these errors were encountered: