Commit 3eadf69a authored by 郭阔's avatar 郭阔

fix(harvest): runlock stale-PID cleanup misparsed lock filename

Lock files are port-<port>.<pid>.lock (two dots); ${f##*.} yielded the
literal 'lock' instead of the PID, so the liveness check always failed
and ANY exiting harvest deleted sibling LIVE locks — with all locks gone
the last exiter then quit the site-shared browser out from under a
still-running sibling harvest (nikkei-world 09:24 exit killed the
browser mid nikkei-markets run; earlier 05:00 run likely degraded the
same way until the 60min watchdog TERM'd it at exit=143).

Parse correctly: basename minus .lock suffix, then last dot-segment.
Self-test: live lock survives, dead-PID lock cleaned.
parent 1fdb4b7b
...@@ -70,13 +70,17 @@ mkdir -p "$_nh_lock_dir" 2>/dev/null || true ...@@ -70,13 +70,17 @@ mkdir -p "$_nh_lock_dir" 2>/dev/null || true
_nh_port="${CDP_PORT_OVERRIDE:-$(nh_cdp_port "$(nh_login_site "$SOURCE")" 2>/dev/null)}" _nh_port="${CDP_PORT_OVERRIDE:-$(nh_cdp_port "$(nh_login_site "$SOURCE")" 2>/dev/null)}"
[ -n "$_nh_port" ] && touch "$_nh_lock_dir/port-${_nh_port}.$$.lock" [ -n "$_nh_port" ] && touch "$_nh_lock_dir/port-${_nh_port}.$$.lock"
_nh_quit_instance() { _nh_quit_instance() {
local skill_dir f pid local skill_dir f base pid
rm -f "$_nh_lock_dir/port-${_nh_port}.$$.lock" 2>/dev/null rm -f "$_nh_lock_dir/port-${_nh_port}.$$.lock" 2>/dev/null
# 清理已被 kill -9 的任务留下的陈旧锁(锁名含 PID) # 清理已被 kill -9 的任务留下的陈旧锁(锁名 port-<port>.<pid>.lock;
# 文件名含两个点,须先去 .lock 后缀再取最后一段,否则会误把活锁当陈旧锁删掉)
for f in "$_nh_lock_dir"/port-"${_nh_port}".*.lock; do for f in "$_nh_lock_dir"/port-"${_nh_port}".*.lock; do
[ -e "$f" ] || continue [ -e "$f" ] || continue
pid="${f##*.}"; pid="${pid%.lock}" base="$(basename "$f" .lock)"
[ -n "$pid" ] && kill -0 "$pid" 2>/dev/null || rm -f "$f" pid="${base##*.}"
if [ -z "$pid" ] || ! kill -0 "$pid" 2>/dev/null; then
rm -f "$f"
fi
done done
# 同端口仍有其他采集任务在跑:不回收共享实例 # 同端口仍有其他采集任务在跑:不回收共享实例
ls "$_nh_lock_dir"/port-"${_nh_port}".*.lock >/dev/null 2>&1 && return 0 ls "$_nh_lock_dir"/port-"${_nh_port}".*.lock >/dev/null 2>&1 && return 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment