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

Binary engine did not handle engine startup failure #142

Closed
jackstefansky opened this issue Mar 7, 2023 · 6 comments · Fixed by #147 or #148
Closed

Binary engine did not handle engine startup failure #142

jackstefansky opened this issue Mar 7, 2023 · 6 comments · Fixed by #147 or #148
Labels
bug Something isn't working

Comments

@jackstefansky
Copy link

jackstefansky commented Mar 7, 2023

It looks like I cannot connect to my postgres database. I suspected that my database URI was incorrect but I can add/read data with prisma studio.

Failing part:

_prismaClient.user.create(
      data: UserCreateInput(
        email: email,
        passwordHash: passwordHash,
        firstName: firstName,
        lastName: lastName,
      ),
    );

The same code causes different issue, but with sqlite ( see #138 )

Stack trace:

#0      IOClient.send (package:http/src/io_client.dart:88:7)
<asynchronous suspension>
#1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:93:32)
<asynchronous suspension>
#2      _withClient (package:http/http.dart:164:12)
<asynchronous suspension>
#3      BinaryEngine._waitPrismaServerReady.<anonymous closure> (package:orm/binary_engine.dart:242:24)
<asynchronous suspension>
#4      RetryOptions.retry (package:retry/retry.dart:131:16)
<asynchronous suspension>
#5      BinaryEngine._createProcess (package:orm/binary_engine.dart:188:19)
<asynchronous suspension>
#6      BinaryEngine.start (package:orm/binary_engine.dart:147:17)
<asynchronous suspension>
#7      UniversalEngine.request (package:orm/universal_engine.dart:58:5)
<asynchronous suspension>
#8      ModelDelegate._execute (package:orm/src/client/model_delegate.dart:36:20)
<asynchronous suspension>
#9      PrismaFluent.queryBuilder.<anonymous closure> (package:orm/src/client/prisma_fluent.dart:37:22)
<asynchronous suspension>
@medz
Copy link
Owner

medz commented Mar 7, 2023

I had this problem when doing dockerization. This is Prisma query engine not starting as expected.

This is a bug because my code calls the local port without checking if the binary engine is started.

The code is in: lib/binary_engine.dart#L197

Add onDone priority to judge whether it is started normally.

But I don't have time to fix it these days, it's an enhancement fix. Just add onDone and it means the startup failed.

Are you free to fix it? I need to write code for my client these days.

@medz medz added the bug Something isn't working label Mar 7, 2023
@medz medz changed the title The remote computer refused the network connection. Binary engine did not handle engine startup failure Mar 7, 2023
@jackstefansky
Copy link
Author

jackstefansky commented Mar 7, 2023

Yeah, I can fix it after work :) Thanks!

@jackstefansky
Copy link
Author

@medz something like this?

    onDone: () => logger.emit(
        Event.error,
        Payload(message: 'Could not start query engine'),
      ),

@jackstefansky
Copy link
Author

jackstefansky commented Mar 7, 2023

I fixed my issue. It looks like i did not provide Datasources object while creating PrismaClient which caused above error.
Maybe let's make datasources parameter required? What do you think @medz?

But I still get:

Exception: Not found UserSession
#0      UserSessionModelDelegateExtension.create.<anonymous closure> (package:prisma_client/prisma_client.dart:7860:15)
#1      _rootRunUnary (dart:async/zone.dart:1406:47)
#2      _CustomZone.runUnary (dart:async/zone.dart:1307:19)
<asynchronous suspension>
#3      Future._chainForeignFuture.<anonymous closure> (dart:async/future_impl.dart:502:19)
<asynchronous suspension>

which is the same error as in #138

@jackstefansky
Copy link
Author

final future =
        query(UserScalarFieldEnum.values.toGraphQLFields()).then((json) {
        
      print(json.runtimeType);
      
      return json is Map
          ? User.fromJson(json.cast<String, dynamic>())
          : throw Exception('Not found User');
    });

I added print(json.runtimeType) in generated prisma_client.dart in order to check why type comparision is failing and it looks like the type of json field is underscored Map ( _Map<String, dynamic> )

@jackstefansky
Copy link
Author

After some more debuging I think it the same issue @nikosportolos mentioned in #138

{errors: [{error: Error in query graph construction: QueryParserError(QueryParserError { path: QueryPath { segments: ["Mutation", "createOneUserSession", "data"] }, error_kind: InputUnionParseError { parsing_errors: [QueryParserError { path: QueryPath { segments: ["Mutation", "createOneUserSession", "data", "UserSessionCreateInput", "expiresAt"] }, error_kind: ValueParseError("Invalid DateTime: '2023-03-08T00:13:24.025584' (must be ISO 8601 compatible). Underlying error: premature end of input") }, QueryParserError { path: QueryPath { segments: ["Mutation", "createOneUserSession", "data", "UserSessionUncheckedCreateInput", "userId"] }, error_kind: RequiredValueNotSetError }] } }), user_facing_error: {is_panic: false, message: Failed to validate the query: `Unable to match input value to any allowed input type for the field. Parse errors: [Query parsing/validation error at `Mutation.createOneUserSession.data.UserSessionCreateInput.expiresAt`: Error parsing value: Invalid DateTime: '2023-03-08T00:13:24.025584' (must be ISO 8601 compatible). Underlying error: premature end of input., Query parsing/validation error at `Mutation.createOneUserSession.data.UserSessionUncheckedCreateInput.userId`: A value is required but not set.]` at `Mutation.createOneUserSession.data`, meta: {query_validation_error: Unable to match input value to any allowed input type for the field. Parse errors: [Query parsing/validation error at `Mutation.createOneUserSession.data.UserSessionCreateInput.expiresAt`: Error parsing value: Invalid DateTime: '2023-03-08T00:13:24.025584' (must be ISO 8601 compatible). Underlying error: premature end of input., Query parsing/validation error at `Mutation.createOneUserSession.data.UserSessionUncheckedCreateInput.userId`: A value is required but not set.], query_position: Mutation.createOneUserSession.data}, error_code: P2009}}]}

@medz medz linked a pull request Mar 10, 2023 that will close this issue
@medz medz closed this as completed in #147 Mar 10, 2023
@medz medz linked a pull request Mar 10, 2023 that will close this issue
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