英文:
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:
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.
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
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 '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 will work If I used a basic code like
void main(){
print('main');
}
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论