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

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

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:

  1. import 'dart:io';
  2. import 'package:shelf/shelf.dart';
  3. import 'package:shelf/shelf_io.dart' as shelf_io;
  4. import 'package:shelf_router/shelf_router.dart' as shelf_router;
  5. import 'package:shelf_static/shelf_static.dart' as shelf_static;
  6. Future main(List<String> arguments) async {
  7. final cascade = Cascade().add(_staticHandler).add(_router);
  8. final server = await shelf_io.serve(cascade.handler, InternetAddress.anyIPv4, 8085);
  9. print('\nServer is running\naddress:${server.address.address}\nhost:${server.address.host}\nport: ${server.port}\n');
  10. }
  11. final _staticHandler = shelf_static.createStaticHandler('public_folder', defaultDocument: 'index.html');
  12. final _router = shelf_router.Router()
  13. ..all('/<ignored|.*>', (Request request) {
  14. return Response.internalServerError();
  15. });

The dependencies:

  1. dependencies:
  2. path: ^1.8.0
  3. html: ^0.15.1
  4. http_parser: ^4.0.2
  5. shelf: ^1.4.0
  6. shelf_router: ^1.1.3
  7. shelf_multipart: ^1.0.0
  8. shelf_static: ^1.1.1
  9. mongo_dart: ^0.9.1
  10. mime: ^1.0.2
  11. mailer: ^6.0.0
  12. synchronized: ^3.0.1
  13. pdf: ^3.10.1

You installed the Dart SDK by following these steps:

  1. sudo apt update
  2. sudo apt install apt-transport-https
  3. wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg
  4. 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
  5. sudo apt update
  6. sudo apt install dart
  7. dart --version
  8. Dart SDK version: 2.19.6 (stable) (Unknown timestamp) on "linux_x64"

It works when you use a basic code like:

  1. void main() {
  2. print('main');
  3. }

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:

  1. import &#39;dart:io&#39;;
  2. import &#39;package:shelf/shelf.dart&#39;;
  3. import &#39;package:shelf/shelf_io.dart&#39; as shelf_io;
  4. import &#39;package:shelf_router/shelf_router.dart&#39; as shelf_router;
  5. import &#39;package:shelf_static/shelf_static.dart&#39; as shelf_static;
  6. Future main(List&lt;String&gt; arguments) async {
  7. final cascade = Cascade().add(_staticHandler).add(_router);
  8. final server = await shelf_io.serve(cascade.handler, InternetAddress.anyIPv4, 8085);
  9. print(&#39;\nServer is running\naddress:${server.address.address}\nhost:${server.address.host}\nport: ${server.port}\n&#39;);
  10. }
  11. final _staticHandler = shelf_static.createStaticHandler(&#39;public_folder&#39;, defaultDocument: &#39;index.html&#39;);
  12. final _router = shelf_router.Router()
  13. ..all(&#39;/&lt;ignored|.*&gt;&#39;, (Request request) {
  14. return Response.internalServerError();
  15. });

The dependencies:

  1. dependencies:
  2. path: ^1.8.0
  3. html: ^0.15.1
  4. http_parser: ^4.0.2
  5. shelf: ^1.4.0
  6. shelf_router: ^1.1.3
  7. shelf_multipart: ^1.0.0
  8. shelf_static: ^1.1.1
  9. mongo_dart: ^0.9.1
  10. mime: ^1.0.2
  11. mailer: ^6.0.0
  12. synchronized: ^3.0.1
  13. pdf: ^3.10.1

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

  1. sudo apt update
  2. sudo apt install apt-transport-https
  3. wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg
  4. 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
  5. sudo apt update
  6. sudo apt install dart
  7. dart --version
  8. Dart SDK version: 2.19.6 (stable) (Unknown timestamp) on &quot;linux_x64&quot;

It will work If I used a basic code like

  1. void main(){
  2. print(&#39;main&#39;);
  3. }

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:

确定