Repository navigation
Description
Hi. I am trying to run studio against microservices with its own database (different schema.prisma files) and I get ETXTBSY error when doing so.
Steps to reproduce:
-
CD to the first microservice. Run
prisma2 studioto open up the studio for the first microservice. Everything works fine here. -
Keep the first instance of studio running, CD to the second microservice and run
prisma2 studioorprisma2 generate. You get this error:
Error: ETXTBSY: text file is busy, open '/home/vignesh/.nvm/versions/node/v13.0.1/lib/node_modules/prisma2/query-engine-debian-openssl-1.1.x'
- Go back to the first microservice, stop the first instance of prisma2 studio and then run the commands in the second microservice, and then it works.
So, at max it is now possible to have only one instance of studio running at this time for me if prisma2 is installed globally as I see. So, when I have microservices with its own databases, not sure how to get multiple instances of studio running to connect to each of them.
STEPS I DID FOR WORKING AROUND THIS PROBLEM:
-
Uninstall the global installation of prisma2
-
Install it as a dev dependency locally specific to each microservice with
npm install prisma2 --save-dev -
Then run studio in each microservice with
npx prisma2 studio --port=5555andnpx prisma2 studio --port=5556and then, it works without any issues.
So, I guess the problem is one binary being used for all instances of studio.
But then, still you have the problem that in every microservice, you need to stop the specific instance of studio to run prisma2 generate against it since it gets locked with itself.
Running Ubuntu 19.10:
Linux vignesh-predator 5.3.0-24-generic #26-Ubuntu SMP Thu Nov 14 01:33:18 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Tried this in prisma2 alpha as well as preview-019. Version:
[email protected], binary version: 8d3279825dadef204b1606d25b3c02db0ca33c91
Activity
tvvignesh commentedon Dec 22, 2019
@divyenduz Hope you remember the discussion we had in slack regarding something similar to this. I have added more details above.
pantharshit00 commentedon Dec 26, 2019
Thanks, I was able to reproduce this on Ubuntu 19.10 but not on a mac:

Studio servers creates a photon worker cluster which is consuming the binary and it is unavailable for use for the other service.
tvvignesh commentedon Dec 26, 2019
@pantharshit00 Great! But curious why that does not happen on a MAC. Interesting.
tvvignesh commentedon Jan 12, 2020
Things are getting crazier now 😢 This bugger came back again today. Everything went smooth so far..
Now, this comes up when running my service via nodemon. Everytime, the service reloads, this error comes up (My src folder where the photon generated folder is there is mounted as a volume) and when nodemon reloads on code changes, I guess the connection is not destroyed causing this issue. Not sure if I am right.
tvvignesh commentedon Jan 13, 2020
@pantharshit00 Provided more details above on how this problem occurs when using nodemon ^^
divyenduz commentedon Jan 17, 2020
@tvvignesh Can you reproduce this issue when studio is not running? In the upcoming release, we are moving studio behind an
--experimentalflag and belive that this issue is linked to Prisma studio's usage of Photon.Can you confirm that this error happens in any case when not using Studio? Thanks
tvvignesh commentedon Jan 18, 2020
@divyenduz Hi. If not studio, it comes many times when I use nodemon as well. For instance, nodemon reloads the script on changes, and since db connection was already there, I guess its being locked or something. So, after hotreload, it gives me the error when it tries to connect to the db again. The error I have mentioned above ^ had come without studio running.
So, I don't think this is specific to studio. Its more of handling the lock I guess.
8 remaining items
timsuchanek commentedon Jan 22, 2020
Thanks a lot for providing the reproduction @tvvignesh!
I tried it out and I can not reproduce it on Mac, however on Arch Linux I can.
The reason is, that the Rust binary in your
distfolder is still running at the moment that nodemon is restarting. This is, however, concretely a problem of your setup. The copyfile commands that is failing here is in your build script in https://github.com/vignesh-test-org/prisma-db-etxbsy/blob/master/package.json#L7, it's not from Prisma.The solution is as @pantharshit00 correctly mentioned, to stop Prisma Client (fka Photon) before restarting. I added a small PR fixing it in your example vignesh-test-org/prisma-db-etxbsy#1
Just that you're aware, you were starting 2 Photon instances, therefore I made a singleton out of it to simplify things. Feel free to throw that code away, it's just to show you how you can fix the error :)
Now back to Prisma: I added a check in our binary copy logic, that it only copies the binary if the target binary doesn't exist yet and the file sizes differ. I expect that to fix the problem for our Prisma Studio users. We will validate that in a bit and close this issue if it did the trick.
RafaelKr commentedon Jan 22, 2020
@timsuchanek Preamble: I don't know how the downloading logic works.
Just a little food for thought: It's possible in a very rare case that a new version of the query-engine has exactly the same size as the version before.
So if the filesize check really is the only check and the version isn't compared in any way, you maybe should either delete the query-engine binary as part of the post-install hook or track it's version in an additional file? This would prevent unpleasant surprises.
timsuchanek commentedon Jan 22, 2020
@RafaelKr that observation is correct. It was a simple calculation: I measured creating a md5 hash of the binaries, which costs about 80ms per binary. That will end up to about
3 * 2 * 80 = 480mson every generate. Instead the filesize check takes about0.5ms. As this case is very unlikely (we're talking about roughly 15 million bytes for the query engine binary), I think this tradeoff is fine for now.Important to note: If you install a new version of
@prisma/clientvia npm, the binary will be cleared and you will get the correct one. This is the recommended, main way to use Prisma Client.The case that you mentioned can only happen if you provide a custom
outputin the generator block of yourschema.prisma:tvvignesh commentedon Jan 23, 2020
@pantharshit00 @timsuchanek Thanks a lot for pointing that out. Didn't realize that nodemon wouldn't clean up the processes. Maybe, the issue is something similar in studio as well possibly.
And thanks for the PR :-) Really helps in understanding how to fix it. Leaving this issue open since you are tracking the same for Studio as well.
Just wondering one thing though (just for my understanding). This kind of issue doesn't happen for me with other libraries like say, mongo, postgres or other DB sdks. Is that because they are installed globally?
@timsuchanek Regarding the file copy logic you were talking about, wondering if using checksum would be cleaner. If checksum changes, you can copy, else ignore it.
timsuchanek commentedon Jan 23, 2020
@tvvignesh and @RafaelKr you're both right, a checksum is the right thing to do.
I did another test and it's just ~ 100ms overhead when running things in parallel.
I just implemented it, so we can all sleep well 😴
RafaelKr commentedon Jan 23, 2020
😂👍
Maybe https://www.npmjs.com/package/filecompare is even faster?
On my laptop it took ~55ms to compare the same binary and it was even much faster in noticing when the binaries were different.
timsuchanek commentedon Jan 30, 2020
Thanks a lot for reporting 🙏
This issue is fixed in the latest alpha version of
prisma2.You can try it out with
npm i -g prisma2@alpha.In case it’s not fixed for you - please let us know and we’ll reopen this issue!
AnandChowdhary commentedon May 27, 2020
@timsuchanek Seems like this was in the alpha in January, I'm assuming this should already be deployed. I'm running beta 6 but still facing this issue.
rm -rf node_modules && npm installseemed to "force" fix it.janpio commentedon May 27, 2020
@AnandChowdhary Would be great if you could create an issue with your full information so we can investigate. This should definitely not happen any more.
omar-dulaimi commentedon Jul 31, 2021
This is happening right now. Was using 2.27.0 then installed 2.18.0
omar-dulaimi commentedon Jul 31, 2021
It only works if you delete node_modules.
janpio commentedon Aug 2, 2021
Open a new issue please if the problem persists.