Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Prisma server not ready" version 3.1.1+ #161

Closed
blopker opened this issue Mar 14, 2023 · 10 comments · Fixed by #162
Closed

"Prisma server not ready" version 3.1.1+ #161

blopker opened this issue Mar 14, 2023 · 10 comments · Fixed by #162
Labels
bug Something isn't working

Comments

@blopker
Copy link
Contributor

blopker commented Mar 14, 2023

Hello! I wanted to surface an issue I ran in to while following the Getting Started guide. After following the guide, then running the final dart program to add a user to the database, I'm getting this error:

~/code/dartprisma/hello main*
❯ dart run
Building package executable...
Built hello:hello.
Hello world: Instance of 'Future<dynamic>'!
quaint::pooled: Starting a postgresql pool with 21 connections. - 2023-03-14 19:35:39.490859Z
Unhandled exception:
PrismaInitializationException: Prisma server is not ready
#0      BinaryEngine._waitPrismaServerReady.<anonymous closure> (package:orm/binary_engine.dart:255:7)
#1      RetryOptions.retry (package:retry/retry.dart:138:24)
<asynchronous suspension>
#2      BinaryEngine._createProcess (package:orm/binary_engine.dart:190:19)
<asynchronous suspension>
#3      BinaryEngine.start (package:orm/binary_engine.dart:149:17)
<asynchronous suspension>
#4      UniversalEngine.request (package:orm/universal_engine.dart:59:5)
<asynchronous suspension>
#5      ModelDelegate._execute (package:orm/src/client/model_delegate.dart:37:20)
<asynchronous suspension>
#6      PrismaFluent.queryBuilder.<anonymous closure> (package:orm/src/client/prisma_fluent.dart:37:22)
<asynchronous suspension>

This error does not happen on version 3.1.0, but starts happening on version 3.1.1 and still happens on 3.1.2. Anything can be done about that?

@medz
Copy link
Owner

medz commented Mar 15, 2023

I guess, we should just do more accurate error output.

I have, I will look into this and let you know.

@medz
Copy link
Owner

medz commented Mar 15, 2023

@blopker Can you provide a minimal example where this error occurs? It is best to create a repository.

@medz medz added the bug Something isn't working label Mar 15, 2023
@blopker
Copy link
Contributor Author

blopker commented Mar 15, 2023

I really just followed the guide at https://prisma.pub/docs/getting-started.html. The code is the same.

I looked at it a bit and added a delay in binary_engine, and it started working:

    return retry<bool>(() async {
      await Future.delayed(Duration(seconds: 1));
      final response = await http.get(url);

It looks like the retry logic isn't looping correctly, and the server isn't starting up fast enough on my system. I'd suggest changing the retry logic to:

return retry<bool>(() async {
      final response = await http.get(url);
      if (response.statusCode == 200) {
        final json = convert.json.decode(response.body);
        if (json['status'].toString().toLowerCase() == 'ok') return true;
      }
      throw PrismaInitializationException(
          message: 'Prisma server is not ready', engine: this);
    });

Instead of throwing the exception in the onRetry callback.

medz added a commit that referenced this issue Mar 15, 2023
…lopker

Fix the binary engine to check the startup status at startup, but the wrong retry logic causes the binary engine to fail to start!

Preview-By: @blopker
Refs: #161
Co-Authored-By: Bo Lopker <757503+blopker@users.noreply.github.com>
@medz
Copy link
Owner

medz commented Mar 15, 2023

@blopker Fixed in v3.1.3 version, Thanks again.

@medz medz closed this as completed Mar 15, 2023
@blopker
Copy link
Contributor Author

blopker commented Mar 15, 2023

Nice! Thanks for the quick turnaround. Hopefully the Prisma people get that C API you wanted done and then there will be none of this server business to deal with.

@medz
Copy link
Owner

medz commented Mar 15, 2023

Nice! Thanks for the quick turnaround. Hopefully the Prisma people get that C API you wanted done and then there will be none of this server business to deal with.

I'm a Rust Apprentice, and I'm overwhelmed by upstream breaking changes.

Issue flagged at prisma/prisma-engines#3757. But Prisma officials seem to be very busy, all I can do is wait.

Maybe someday I'll create a PR for them when I feel competent enough to edit the Prisma engine's Rust code. This is great for me, since bringing Prisma into Flutter has always been a goal of mine.

@blopker
Copy link
Contributor Author

blopker commented Mar 15, 2023

Hm, the fix didn't quite work. It looks like the http library is throwing an exception when the server isn't up yet. I think the code needs to retry on any exception.

@medz medz reopened this Mar 15, 2023
@medz
Copy link
Owner

medz commented Mar 15, 2023

Hm, the fix didn't quite work. It looks like the http library is throwing an exception when the server isn't up yet. I think the code needs to retry on any exception.

I found it too, I'll re-fix it

@medz
Copy link
Owner

medz commented Mar 15, 2023

@blopker Because I paid one-sided attention to the abnormal retry of the function body before, and ignored the IO related, now I fixed it in v3.1.4 👉https://github.com/odroe/prisma-dart/releases/tag/orm-v3.1.4

@blopker
Copy link
Contributor Author

blopker commented Mar 15, 2023

Works now! Thanks @medz. Another thing I noticed is that if _waitPrismaServerReady does fail, but the server does start, the Process object that's created doesn't get cleaned up. When I was testing I had a dozen or so servers running without a parent. I think adding a kill in _createProcess if things go sideways might be good:

    // Wait for ready.
    if (await _waitPrismaServerReady()) {
      return process;
    }
   process.kill();

It's cool you're working on this. There's not really a good solution to database management for Dart yet. This is going to be a huge win for this ecosystem. I was under the impression Prisma re-wrote the server in Rust specifically to support more languages, but I guess they never got that far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants