Skip to content

Commit

Permalink
Fix: [Server] システムのポートや死んだプロセスのポートがあると例外で落ちるのを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
xtne6f authored and tsukumijima committed Oct 7, 2023
1 parent 2ffb43c commit ae297b3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions server/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,15 @@ def validate_port(cls, port: int, info: FieldValidationInfo) -> int:
## サーバーの起動中に再度バリデーションが実行された際に、ポートが使用中と判定されてしまうのを防ぐためのもの
## 自動リロードモードでの reloader process や Akebi は KonomiTV サーバーの子プロセスになるので、
## プロセスの親プロセスの PID が一致するかもチェックする
process = psutil.Process(conn.pid)
if ((process.pid == current_process.pid) or
(process.pid == current_process.ppid()) or
(process.ppid() == current_process.pid) or
(process.ppid() == current_process.ppid())):
continue
try:
process = psutil.Process(conn.pid)
if ((process.pid == current_process.pid) or
(process.pid == current_process.ppid()) or
(process.ppid() == current_process.pid) or
(process.ppid() == current_process.ppid())):
continue
except Exception:
pass
# 使用中のポートに追加
if conn.laddr is not None:
used_ports.append(cast(Any, conn.laddr).port)
Expand Down

0 comments on commit ae297b3

Please sign in to comment.