Skip to content

Commit a63219f

Browse files
committed
fix: 获取服务器信息时导致崩溃
fix: 某些情况下在控制台输入导致崩溃 ci: 添加docker
1 parent ac4256a commit a63219f

File tree

4 files changed

+83
-8
lines changed

4 files changed

+83
-8
lines changed

.github/workflows/docker-push.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
on:
2+
push:
3+
paths:
4+
- 'Dockerfile'
5+
- '**/*.cs'
6+
- '**/*.csproj'
7+
8+
workflow_dispatch:
9+
10+
jobs:
11+
push:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up QEMU
17+
uses: docker/setup-qemu-action@v3
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
22+
- name: Login to Github Registry
23+
uses: docker/login-action@v3
24+
if: github.event_name != 'pull_request'
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.repository_owner }}
28+
password: ${{ secrets.GH_TOKEN }}
29+
30+
- name: Extract metadata (tags, labels) for Docker
31+
id: meta
32+
uses: docker/metadata-action@v5
33+
with:
34+
images: |
35+
ghcr.io/${{ github.repository_owner }}/serein.cli
36+
tags: |
37+
type=edge
38+
type=sha,event=branch
39+
type=ref,event=tag
40+
41+
- name: Build and push
42+
uses: docker/build-push-action@v5
43+
with:
44+
context: .
45+
file: "Dockerfile"
46+
push: ${{ github.event_name != 'pull_request' }}
47+
tags: ${{ steps.meta.outputs.tags }}
48+
labels: ${{ steps.meta.outputs.labels }}
49+
platforms: linux/amd64, linux/arm64, linux/arm

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
2+
3+
WORKDIR /src
4+
COPY . .
5+
6+
ARG TARGETARCH
7+
RUN dotnet publish src/Serein.Cli -a $TARGETARCH -c Release -o /app/bin
8+
9+
WORKDIR /app/bin
10+
ENV DOTNET_EnableWriteXorExecute=0
11+
12+
RUN echo "#!/bin/sh \r\n/app/bin/Serein.Cli" > /app/bin/serein-entrypoint.sh
13+
RUN chmod +x /app/bin/serein-entrypoint.sh
14+
15+
ENTRYPOINT [ "/app/bin/serein-entrypoint.sh" ]

src/Serein.Cli/Services/Interaction/InputLoopService.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,22 @@ out var server
8181
Console.CancelKeyPress -= IgnoreCtrlC;
8282
flag = false;
8383
}
84-
var response = prompt.ReadLineAsync().Await();
8584

86-
if (response.IsSuccess)
85+
try
8786
{
88-
ProcessInput(response.Text);
87+
var response = prompt.ReadLineAsync().Await();
88+
89+
if (response.IsSuccess)
90+
{
91+
ProcessInput(response.Text);
92+
}
93+
}
94+
catch (Exception e)
95+
{
96+
_logger.LogError(
97+
e,
98+
"读取输入时发生错误。若此错误持续出现,请尝试关闭彩色输出"
99+
);
89100
}
90101
}
91102
}

src/Serein.Core/Services/Servers/ServerBase.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ ReactionTrigger reactionManager
7070
_commandHistory = [];
7171
_cache = [];
7272
_updateTimer = new(2000) { AutoReset = true };
73-
_updateTimer.Elapsed += (_, _) => UpdateInfo();
73+
_updateTimer.Elapsed += (_, _) => Task.Run(UpdateInfo);
7474
_info = new();
7575
PluginManager = new(this);
7676

77-
ServerStatusChanged += (_, _) => UpdateInfo();
77+
ServerStatusChanged += (_, _) => Task.Run(UpdateInfo);
7878
}
7979

8080
protected abstract void StartProcess();
@@ -441,7 +441,7 @@ private void WaitAndRestart()
441441
);
442442
}
443443

444-
private async Task UpdateInfo()
444+
private void UpdateInfo()
445445
{
446446
if (!Status && _process is null)
447447
{
@@ -454,7 +454,7 @@ private async Task UpdateInfo()
454454
_info.CpuUsage = 0;
455455
return;
456456
}
457-
else if (_process is null)
457+
else if (_process is null || _process.HasExited)
458458
{
459459
return;
460460
}
@@ -469,7 +469,7 @@ private async Task UpdateInfo()
469469

470470
if (Configuration.PortIPv4 >= 0)
471471
{
472-
await Task.Run(() => _info.Stat = new("127.0.0.1", (ushort)Configuration.PortIPv4));
472+
_info.Stat = new("127.0.0.1", (ushort)Configuration.PortIPv4);
473473
}
474474
}
475475
}

0 commit comments

Comments
 (0)