grpc / grpc-dart

The Dart language implementation of gRPC.
https://pub.dev/packages/grpc
Apache License 2.0
861 stars 271 forks source link

Crash when compiling null #578

Closed Nexushunter closed 2 years ago

Nexushunter commented 2 years ago

Note I'm not sure if this should be filed here. I am looking to use a dart based grpc server. I have generated my protos and have trialled a go sample which works. But Im not having the same such luck. This doesn't occur when then server is not in a container class.

  grpc:
    dependency: "direct main"
    description:
      name: grpc
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.0.2"
  protobuf:
    dependency: "direct main"
    description:
      name: protobuf
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.1.0"
protoc_plugin:
    dependency: "direct dev"
    description:
      name: protoc_plugin
      url: "https://pub.dartlang.org"
    source: hosted
    version: "20.0.1"
Flutter 3.3.2 • channel stable • git@github.com:flutter/flutter.git
Framework • revision e3c29ec00c (2 days ago) • 2022-09-14 08:46:55 -0500
Engine • revision a4ff2c53d8
Tools • Dart 2.18.1 • DevTools 2.15.0

Repro steps

  1. Use sample provided below
  2. run dart -v lib/main.dart
  3. Crashes

Expected result: server application to start

Actual result:

Crash when compiling null,
at character offset null:
Null check operator used on a null value
#0      InferableTypeBuilderMixin.type (package:front_end/src/fasta/builder/type_builder.dart:392:29)
#1      InferableTypeBuilder.inferType (package:front_end/src/fasta/builder/omitted_type_builder.dart:155:12)
#2      SourceLoader.performTopLevelInference (package:front_end/src/fasta/source/source_loader.dart:2358:19)
#3      KernelTarget.buildOutlines.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:532:14)
<asynchronous suspension>
#4      withCrashReporting (package:front_end/src/fasta/crash.dart:122:12)
<asynchronous suspension>
#5      _buildInternal (package:front_end/src/kernel_generator_impl.dart:139:7)
<asynchronous suspension>
#6      withCrashReporting (package:front_end/src/fasta/crash.dart:122:12)
<asynchronous suspension>
#7      generateKernel.<anonymous closure> (package:front_end/src/kernel_generator_impl.dart:47:12)
<asynchronous suspension>
#8      generateKernel (package:front_end/src/kernel_generator_impl.dart:46:10)
<asynchronous suspension>
#9      kernelForModule (package:front_end/src/api_prototype/kernel_generator.dart:100:11)
<asynchronous suspension>
#10     SingleShotCompilerWrapper.compileInternal (file:///b/s/w/ir/cache/builder/sdk/pkg/vm/bin/kernel_service.dart:412:11)
<asynchronous suspension>
#11     Compiler.compile.<anonymous closure> (file:///b/s/w/ir/cache/builder/sdk/pkg/vm/bin/kernel_service.dart:221:45)
<asynchronous suspension>
#12     _processLoadRequest (file:///b/s/w/ir/cache/builder/sdk/pkg/vm/bin/kernel_service.dart:914:37)
<asynchronous suspension>

#0      InferableTypeBuilderMixin.type (package:front_end/src/fasta/builder/type_builder.dart:392:29)
#1      InferableTypeBuilder.inferType (package:front_end/src/fasta/builder/omitted_type_builder.dart:155:12)
#2      SourceLoader.performTopLevelInference (package:front_end/src/fasta/source/source_loader.dart:2358:19)
#3      KernelTarget.buildOutlines.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:532:14)
<asynchronous suspension>
#4      withCrashReporting (package:front_end/src/fasta/crash.dart:122:12)
<asynchronous suspension>
#5      _buildInternal (package:front_end/src/kernel_generator_impl.dart:139:7)
<asynchronous suspension>
#6      withCrashReporting (package:front_end/src/fasta/crash.dart:122:12)
<asynchronous suspension>
#7      generateKernel.<anonymous closure> (package:front_end/src/kernel_generator_impl.dart:47:12)
<asynchronous suspension>
#8      generateKernel (package:front_end/src/kernel_generator_impl.dart:46:10)
<asynchronous suspension>
#9      kernelForModule (package:front_end/src/api_prototype/kernel_generator.dart:100:11)
<asynchronous suspension>
#10     SingleShotCompilerWrapper.compileInternal (file:///b/s/w/ir/cache/builder/sdk/pkg/vm/bin/kernel_service.dart:412:11)
<asynchronous suspension>
#11     Compiler.compile.<anonymous closure> (file:///b/s/w/ir/cache/builder/sdk/pkg/vm/bin/kernel_service.dart:221:45)
<asynchronous suspension>
#12     _processLoadRequest (file:///b/s/w/ir/cache/builder/sdk/pkg/vm/bin/kernel_service.dart:914:37)
<asynchronous suspension>

Process finished with exit code 252

Details

main.dart

import 'package:testing_issue/src/server/grpc_server.dart';
import 'package:logging/logging.dart';

void main() async {
  final _log = Logger('GRPC Server Test');
  final port = 9091;
  final server = GRPCServer();
  await server.start();
  _log.finest('Server listening on port: $port');
} 

src/server/grpc_server.dart

import 'dart:io';

import 'package:grpc/grpc.dart';
import 'package:logging/logging.dart';

class GRPCServer {
  static final _log = Logger('GRPCServer');
  late final Server server;
  late final int port;

  GRPCServer({this.port = 9091}) {
    server = Server([]);
  }

  Future<void> start() async {
    // this works when run directly in main
    await server.serve(
      address: InternetAddress(
        'localhost',
        type: InternetAddressType.unix,
      ),
      port: port,
    );
  }
}
mraleph commented 2 years ago

Looks like a crash in the Dart front-end. Thanks for providing the repro! There is a similar issue already reported: https://github.com/dart-lang/sdk/issues/49641. Please follow there for updates.