Skip to content

ETXTBSY error when an instance of prisma2 is already running  #1209

Closed

Description

@tvvignesh

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:

  1. CD to the first microservice. Run prisma2 studio to open up the studio for the first microservice. Everything works fine here.

  2. Keep the first instance of studio running, CD to the second microservice and run prisma2 studio or prisma2 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'
  1. 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:

  1. Uninstall the global installation of prisma2

  2. Install it as a dev dependency locally specific to each microservice with npm install prisma2 --save-dev

  3. Then run studio in each microservice with npx prisma2 studio --port=5555 and npx prisma2 studio --port=5556 and 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

  1. tvvignesh commented on Dec 22, 2019

    @tvvignesh
    ContributorAuthor

    @divyenduz Hope you remember the discussion we had in slack regarding something similar to this. I have added more details above.

  2. pantharshit00 commented on Dec 26, 2019

    @pantharshit00
    Contributor

    Thanks, I was able to reproduce this on Ubuntu 19.10 but not on a mac:
    image

    Studio servers creates a photon worker cluster which is consuming the binary and it is unavailable for use for the other service.

  3. added
    bug/2-confirmed
    kind/bug
    on Dec 26, 2019
  4. tvvignesh commented on Dec 26, 2019

    @tvvignesh
    ContributorAuthor

    @pantharshit00 Great! But curious why that does not happen on a MAC. Interesting.

  5. tvvignesh commented on Jan 12, 2020

    @tvvignesh
    ContributorAuthor

    Things are getting crazier now 😢 This bugger came back again today. Everything went smooth so far..

    > npx tsc && npx copyfiles -u 1 -e "src/**/*.ts" "src/**/*.*" dist/
    
    [Error: ETXTBSY: text file is busy, copyfile 'src/generated/photon/runtime/query-engine-debian-openssl-1.1.x' -> 'dist/generated/photon/runtime/query-engine-debian-openssl-1.1.x'] {
      errno: -26,
      code: 'ETXTBSY',
      syscall: 'copyfile',
      path: 'src/generated/photon/runtime/query-engine-debian-openssl-1.1.x',
      dest: 'dist/generated/photon/runtime/query-engine-debian-openssl-1.1.x'
    }
    

    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.

  6. tvvignesh commented on Jan 13, 2020

    @tvvignesh
    ContributorAuthor

    @pantharshit00 Provided more details above on how this problem occurs when using nodemon ^^

  7. added this to the Preview 21 milestone on Jan 17, 2020
  8. divyenduz commented on Jan 17, 2020

    @divyenduz

    @tvvignesh Can you reproduce this issue when studio is not running? In the upcoming release, we are moving studio behind an --experimental flag 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

  9. tvvignesh commented on Jan 18, 2020

    @tvvignesh
    ContributorAuthor

    @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.

  10. 8 remaining items

  11. timsuchanek commented on Jan 22, 2020

    @timsuchanek
    Contributor

    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 dist folder 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.

  12. RafaelKr commented on Jan 22, 2020

    @RafaelKr
    Contributor

    @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.

  13. timsuchanek commented on Jan 22, 2020

    @timsuchanek
    Contributor

    @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 = 480ms on every generate. Instead the filesize check takes about 0.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/client via 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 output in the generator block of your schema.prisma:

    generator client {
      provider = "prisma-client-js"
      output = "./generated/client"
    }
  14. tvvignesh commented on Jan 23, 2020

    @tvvignesh
    ContributorAuthor

    @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.

  15. timsuchanek commented on Jan 23, 2020

    @timsuchanek
    Contributor

    @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 😴

  16. RafaelKr commented on Jan 23, 2020

    @RafaelKr
    Contributor

    😂👍

    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.

  17. removed their assignment
    on Jan 30, 2020
  18. timsuchanek commented on Jan 30, 2020

    @timsuchanek
    Contributor

    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!

  19. AnandChowdhary commented on May 27, 2020

    @AnandChowdhary

    @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 install seemed to "force" fix it.

  20. janpio commented on May 27, 2020

    @janpio
    Contributor

    @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.

  21. omar-dulaimi commented on Jul 31, 2021

    @omar-dulaimi
    Contributor

    This is happening right now. Was using 2.27.0 then installed 2.18.0

  22. omar-dulaimi commented on Jul 31, 2021

    @omar-dulaimi
    Contributor

    It only works if you delete node_modules.

  23. janpio commented on Aug 2, 2021

    @janpio
    Contributor

    Open a new issue please if the problem persists.

  24. locked as resolved and limited conversation to collaborators on Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug/2-confirmedkind/bugtopic: binarytopic: studio

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions