Skip to content

Commit

Permalink
complete: fix a task scheduling bug of referencing two different clocks
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Aug 31, 2021
1 parent 0f6a083 commit fea5f5b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/core-complete.sh
Expand Up @@ -5948,11 +5948,7 @@ function ble/complete/auto-complete.idle {
[[ $_ble_edit_str ]] || return 0

# bleopt_complete_auto_delay だけ経過してから処理
local rest_delay=$((bleopt_complete_auto_delay-ble_util_idle_elapsed))
if ((rest_delay>0)); then
ble/util/idle.sleep "$rest_delay"
return 0
fi
ble/util/idle.sleep-until $((_idle_clock_start+bleopt_complete_auto_delay)) checked && return 0

ble/complete/auto-complete.impl
}
Expand Down
1 change: 1 addition & 0 deletions memo/ChangeLog.md
Expand Up @@ -149,6 +149,7 @@
- decode, canvas, etc.: explicitly treat CSI arguments as decimal numbers (reported by GorrillaRibs) `#D1625` c6473b7 2ea48d7
- history: fix the vanishing history entry used for `ble-attach` `#D1629` eb34061
- global: work around readonly `TMOUT` (reported by farmerbobathan) `#D1630` 44e6ec1
- complete: fix a task scheduling bug of referencing two different clocks `#D1636` 0000000

## Optimization

Expand Down
42 changes: 42 additions & 0 deletions note.txt
Expand Up @@ -4914,6 +4914,48 @@ bash_tips
Done (実装ログ)
-------------------------------------------------------------------------------

2021-09-01

* auto-complete: idle.sleep で異なる時計を参照していた事による無限ループ (reported by rashil2000) [#D1636]
https://github.com/akinomyoga/ble.sh/issues/133

msys2 で auto-complete が特定の状況で実行されないという報告だったが、自分の
手元で complete_timeout_auto= にしてみたらどうやら無限ループになっている気
がする。調べてみると idle.sleep しているのに sleep していない。と思ったら、
どうやら異なる時計を参照していた為に msleep が skip されて、無限に msleep
の要求をし続けている状態になっていた。

これを直したらちゃんと補完候補が表示される様になった。

然しこれについては過去に修正した様な気がする。過去に修正した時の修正漏れか
或いは逆方向に間違えて修正したか。再度確認する必要がある。

* ble/complete/auto-menu.idle の #D1597 での修正

53dd018e で他の箇所を類似の問題により isleep から sleep に切り替えている。
#D1597 である。一方で今回問題になっている箇所は最初から sleep だった様だ。
#D1597 に詳しく説明が書かれている。

改めて実装を確認する。auto-menu.idle は _idle_clock_start を元にしてい
る。_idle_clock_start は ble/util/idle.clock を元にしている。
ble/util/idle.clock は色々実装を切り替えているので環境によって異なる。ま
た、idle.sleep もまた ble/util/idle.clock を元にしている。

* 今回の ble/complete/auto-complete.idle に関しては、唯単に idle.sleep を要
求しているだけの様に見える。但し、最後にユーザー入力があって以降の経過時
間を考慮に入れる為に ble_util_idle_elapsed を用いている。この
ble_util_idle_elapsed は _ble_util_idle_sclock-_idle_sclock_start を元に
していて、更にこれらは ble/util/idle/.sleep で積算される。

うーん。つまり、ble_util_idle_elapsed を参照する限りは isleep を使う必要
があるという事。一方で auto-complete の delay を処理するのは isleep に基
づくべきか sleep に基づくべきかという疑問もある。

* また macOS の 100% も関係しているかもしれない。報告によると履歴のロードに
関係しているという事だが、nawk が走っている間ずっと CPU が動いているとい
う状態になっている可能性もある。と思ったがそうでもなかった。そもそも履歴
の初期化では sleep は行っていない。

2021-08-30

* edit: command-help が効かなくなっている [#D1635]
Expand Down

0 comments on commit fea5f5b

Please sign in to comment.