Dart服务器:在使用dart run后,终端始终返回Killed。

huangapple go评论67阅读模式
英文:

Dart Server: The terminal always return Killed after using dart run

问题

This dart server project works successfully when running on my PC. But when I ran it on the server, I got this error:

Dart服务器:在使用dart run后,终端始终返回Killed。

My server is Ubuntu 20.04 (LTS) x64. I tried it with this code:

import 'dart:io';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_router/shelf_router.dart' as shelf_router;
import 'package:shelf_static/shelf_static.dart' as shelf_static;

Future main(List<String> arguments) async {
  final cascade = Cascade().add(_staticHandler).add(_router);
  final server = await shelf_io.serve(cascade.handler, InternetAddress.anyIPv4, 8085);
  print('\nServer is running\naddress:${server.address.address}\nhost:${server.address.host}\nport: ${server.port}\n');
}

final _staticHandler = shelf_static.createStaticHandler('public_folder', defaultDocument: 'index.html');
final _router = shelf_router.Router()
  ..all('/<ignored|.*>', (Request request) {
    return Response.internalServerError();
  });

The dependencies:

dependencies:
  path: ^1.8.0
  html: ^0.15.1
  http_parser: ^4.0.2
  shelf: ^1.4.0
  shelf_router: ^1.1.3
  shelf_multipart: ^1.0.0
  shelf_static: ^1.1.1
  mongo_dart: ^0.9.1
  mime: ^1.0.2
  mailer: ^6.0.0
  synchronized: ^3.0.1
  pdf: ^3.10.1

You installed the Dart SDK by following these steps:

sudo apt update
sudo apt install apt-transport-https
wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg
echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list
sudo apt update
sudo apt install dart

dart --version
Dart SDK version: 2.19.6 (stable) (Unknown timestamp) on "linux_x64"

It works when you use a basic code like:

void main() {
  print('main');
}

Can you provide more details about the specific error you encountered on the server?

英文:

This dart server project work successfully when running on my PC.
But when I ran it on the server, I got this.
Dart服务器:在使用dart run后,终端始终返回Killed。

My server is Ubuntu 20.04 (LTS) x64.
I tried it with this code:

import &#39;dart:io&#39;;
import &#39;package:shelf/shelf.dart&#39;;
import &#39;package:shelf/shelf_io.dart&#39; as shelf_io;
import &#39;package:shelf_router/shelf_router.dart&#39; as shelf_router;
import &#39;package:shelf_static/shelf_static.dart&#39; as shelf_static;

Future main(List&lt;String&gt; arguments) async {
  final cascade = Cascade().add(_staticHandler).add(_router);
  final server = await shelf_io.serve(cascade.handler, InternetAddress.anyIPv4, 8085);
  print(&#39;\nServer is running\naddress:${server.address.address}\nhost:${server.address.host}\nport: ${server.port}\n&#39;);
}



final _staticHandler = shelf_static.createStaticHandler(&#39;public_folder&#39;, defaultDocument: &#39;index.html&#39;);
final _router = shelf_router.Router()
  ..all(&#39;/&lt;ignored|.*&gt;&#39;, (Request request) {
    return Response.internalServerError();
  });

The dependencies:

dependencies:
  path: ^1.8.0
  html: ^0.15.1
  http_parser: ^4.0.2
  shelf: ^1.4.0
  shelf_router: ^1.1.3
  shelf_multipart: ^1.0.0
  shelf_static: ^1.1.1
  mongo_dart: ^0.9.1
  mime: ^1.0.2
  mailer: ^6.0.0
  synchronized: ^3.0.1
  pdf: ^3.10.1

I install the Dart SDK by following this https://dart.dev/get-dart

sudo apt update
sudo apt install apt-transport-https
wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg
echo &#39;deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main&#39; | sudo tee /etc/apt/sources.list.d/dart_stable.list
sudo apt update
sudo apt install dart

dart --version
Dart SDK version: 2.19.6 (stable) (Unknown timestamp) on &quot;linux_x64&quot;

It will work If I used a basic code like

void main(){
  print(&#39;main&#39;);
}

What happens?

答案1

得分: 0

增加内存从0.5 GB到1 GB后,它可以正常工作。
但我想知道为什么像这样的基本代码会使用这么多内存。
这是一个新服务器,只安装了NGINX、MongoDB和Dart SDK。
这很奇怪。

英文:

It works after I increase the memory from 0.5 GB to 1 GB.
But I wonder why basic code like that is using so much memory.
This is a new server just install NGINX, MongoDB, and Dart SDK.
It's strange.

huangapple
  • 本文由 发表于 2023年5月10日 22:14:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76219483.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定