Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Pid file locking #5676

Merged
merged 13 commits into from Mar 6, 2024
Merged

Implement Pid file locking #5676

merged 13 commits into from Mar 6, 2024

Conversation

crodas
Copy link
Contributor

@crodas crodas commented Feb 28, 2024

Description

Fixes #5633

Added functionality to create and manage a lock file containing the process ID (pid) of the running instance of the software. This mechanism prevents multiple instances of the software from running simultaneously by checking the existence and content of the lock file. If the lock file exists and contains a valid pid, the struct will error gracefully to avoid conflicts. If the lock file is missing or contains an invalid pid, the struct will proceed by removing the file. This ensures that only one instance of the software can run at a time and it avoids stale locking to prevent future instances

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@crodas crodas requested a review from a team February 28, 2024 23:06
@crodas crodas self-assigned this Feb 28, 2024
Copy link

Benchmark for 02156fa

Click to view benchmark
Test Base PR %
code_action 5.1±0.04ms 5.2±0.11ms +1.96%
code_lens 292.8±7.77ns 292.2±11.74ns -0.20%
compile 3.0±0.04s 3.0±0.03s 0.00%
completion 4.8±0.04ms 4.7±0.14ms -2.08%
did_change_with_caching 2.9±0.01s 2.8±0.03s -3.45%
document_symbol 994.5±17.10µs 965.6±23.52µs -2.91%
format 72.6±0.81ms 73.0±1.38ms +0.55%
goto_definition 365.7±5.69µs 359.2±5.52µs -1.78%
highlight 8.9±0.21ms 8.8±0.27ms -1.12%
hover 534.6±7.70µs 556.1±7.25µs +4.02%
idents_at_position 122.9±0.34µs 121.7±1.06µs -0.98%
inlay_hints 651.6±23.34µs 654.6±31.70µs +0.46%
on_enter 482.1±12.16ns 482.0±7.70ns -0.02%
parent_decl_at_position 3.6±0.02ms 3.6±0.03ms 0.00%
prepare_rename 367.5±7.34µs 358.4±7.69µs -2.48%
rename 9.1±0.18ms 9.1±0.05ms 0.00%
semantic_tokens 1081.3±14.12µs 1046.4±28.81µs -3.23%
token_at_position 359.9±3.62µs 347.0±3.36µs -3.58%
tokens_at_position 3.8±0.12ms 3.6±0.05ms -5.26%
tokens_for_file 488.1±3.46µs 404.7±3.45µs -17.09%
traverse 39.1±1.03ms 39.0±1.43ms -0.26%

@crodas crodas enabled auto-merge (squash) February 28, 2024 23:35
Copy link

Benchmark for 25d18f8

Click to view benchmark
Test Base PR %
code_action 5.1±0.11ms 5.2±0.13ms +1.96%
code_lens 291.2±12.51ns 295.1±11.63ns +1.34%
compile 2.9±0.04s 2.9±0.02s 0.00%
completion 4.7±0.07ms 4.7±0.03ms 0.00%
did_change_with_caching 2.8±0.03s 2.8±0.05s 0.00%
document_symbol 973.6±32.04µs 959.4±11.02µs -1.46%
format 72.7±1.00ms 72.2±0.55ms -0.69%
goto_definition 372.2±4.48µs 361.6±8.38µs -2.85%
highlight 8.8±0.18ms 8.8±0.24ms 0.00%
hover 543.6±7.40µs 536.0±8.03µs -1.40%
idents_at_position 123.3±0.41µs 123.8±1.13µs +0.41%
inlay_hints 662.7±10.53µs 659.8±24.67µs -0.44%
on_enter 494.8±16.36ns 479.5±15.29ns -3.09%
parent_decl_at_position 3.6±0.03ms 3.6±0.02ms 0.00%
prepare_rename 364.8±4.99µs 363.2±7.91µs -0.44%
rename 9.1±0.19ms 9.2±0.21ms +1.10%
semantic_tokens 1084.9±16.25µs 1075.0±44.92µs -0.91%
token_at_position 364.8±2.52µs 358.4±4.38µs -1.75%
tokens_at_position 3.6±0.03ms 3.6±0.03ms 0.00%
tokens_for_file 426.5±5.52µs 412.1±3.56µs -3.38%
traverse 37.6±0.99ms 37.4±0.91ms -0.53%

forc-util/src/fs_locking.rs Outdated Show resolved Hide resolved
forc-util/src/fs_locking.rs Outdated Show resolved Hide resolved
Copy link

Benchmark for f1b1c65

Click to view benchmark
Test Base PR %
code_action 5.0±0.17ms 4.9±0.17ms -2.00%
code_lens 279.0±12.84ns 278.7±11.36ns -0.11%
compile 2.8±0.04s 2.8±0.03s 0.00%
completion 4.5±0.14ms 4.4±0.11ms -2.22%
did_change_with_caching 2.7±0.03s 2.7±0.02s 0.00%
document_symbol 921.1±47.66µs 902.0±29.62µs -2.07%
format 69.9±1.64ms 69.5±1.55ms -0.57%
goto_definition 360.4±9.68µs 346.0±11.74µs -4.00%
highlight 8.5±0.31ms 8.5±0.23ms 0.00%
hover 517.0±14.17µs 517.5±16.67µs +0.10%
idents_at_position 116.3±2.52µs 117.6±3.02µs +1.12%
inlay_hints 632.3±40.30µs 691.3±39.86µs +9.33%
on_enter 454.6±11.34ns 457.3±14.71ns +0.59%
parent_decl_at_position 3.4±0.07ms 3.4±0.07ms 0.00%
prepare_rename 360.6±10.30µs 340.3±9.45µs -5.63%
rename 8.8±0.31ms 8.7±0.22ms -1.14%
semantic_tokens 1019.2±29.78µs 1002.8±31.93µs -1.61%
token_at_position 339.6±7.99µs 339.4±8.36µs -0.06%
tokens_at_position 3.4±0.06ms 3.4±0.08ms 0.00%
tokens_for_file 397.4±14.45µs 381.7±6.21µs -3.95%
traverse 36.4±1.22ms 35.9±0.97ms -1.37%

@crodas
Copy link
Contributor Author

crodas commented Feb 29, 2024

Screen.Recording.2024-02-29.at.19.50.39.mov

forc-util/src/fs_locking.rs Outdated Show resolved Hide resolved
forc-plugins/forc-fmt/src/main.rs Outdated Show resolved Hide resolved
forc-util/src/fs_locking.rs Outdated Show resolved Hide resolved
sway-lsp/src/core/document.rs Outdated Show resolved Hide resolved
forc-util/src/fs_locking.rs Show resolved Hide resolved
forc-util/src/fs_locking.rs Outdated Show resolved Hide resolved
forc-util/src/fs_locking.rs Show resolved Hide resolved
sway-lsp/src/core/document.rs Outdated Show resolved Hide resolved
forc-util/src/fs_locking.rs Outdated Show resolved Hide resolved
forc-util/src/fs_locking.rs Show resolved Hide resolved
@crodas crodas force-pushed the lsp-lock-stale-recovery branch 2 times, most recently from 1a40603 to 3f0b0da Compare February 29, 2024 23:33
Copy link

github-actions bot commented Mar 1, 2024

Benchmark for 052fb92

Click to view benchmark
Test Base PR %
code_action 5.2±0.33ms 5.2±0.06ms 0.00%
code_lens 291.2±6.98ns 300.4±11.66ns +3.16%
compile 2.9±0.03s 2.9±0.03s 0.00%
completion 4.6±0.02ms 4.7±0.28ms +2.17%
did_change_with_caching 2.9±0.05s 2.8±0.04s -3.45%
document_symbol 1009.1±44.25µs 974.6±9.75µs -3.42%
format 73.5±1.28ms 74.0±0.81ms +0.68%
goto_definition 370.4±3.27µs 360.5±6.34µs -2.67%
highlight 8.8±0.04ms 8.8±0.18ms 0.00%
hover 537.6±6.94µs 530.8±18.33µs -1.26%
idents_at_position 123.9±0.60µs 122.5±1.66µs -1.13%
inlay_hints 659.5±13.19µs 654.7±25.03µs -0.73%
on_enter 487.3±34.07ns 477.9±21.27ns -1.93%
parent_decl_at_position 3.6±0.03ms 3.6±0.03ms 0.00%
prepare_rename 363.8±2.77µs 362.1±5.17µs -0.47%
rename 9.2±0.23ms 9.1±0.09ms -1.09%
semantic_tokens 1055.1±7.95µs 1047.3±35.11µs -0.74%
token_at_position 360.2±9.30µs 351.7±2.63µs -2.36%
tokens_at_position 3.6±0.04ms 3.6±0.08ms 0.00%
tokens_for_file 411.9±3.03µs 412.3±3.77µs +0.10%
traverse 37.6±1.01ms 37.8±0.88ms +0.53%

Copy link
Member

@JoshuaBatty JoshuaBatty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off to a good start, but it would be good to address my concern about the sysinfo crate before this lands.

forc-util/Cargo.toml Outdated Show resolved Hide resolved
sway-lsp/src/core/document.rs Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Mar 1, 2024

Benchmark for a5ef4d2

Click to view benchmark
Test Base PR %
code_action 5.1±0.12ms 5.2±0.16ms +1.96%
code_lens 296.3±7.61ns 331.0±14.59ns +11.71%
compile 2.9±0.03s 2.9±0.02s 0.00%
completion 4.7±0.02ms 4.7±0.02ms 0.00%
did_change_with_caching 2.8±0.03s 2.8±0.03s 0.00%
document_symbol 954.9±19.15µs 1002.6±33.43µs +5.00%
format 72.5±1.02ms 75.8±1.14ms +4.55%
goto_definition 361.1±9.69µs 373.2±18.71µs +3.35%
highlight 8.8±0.03ms 8.9±0.24ms +1.14%
hover 529.1±9.20µs 538.8±7.80µs +1.83%
idents_at_position 122.1±0.37µs 121.0±0.41µs -0.90%
inlay_hints 652.5±24.27µs 667.3±25.97µs +2.27%
on_enter 476.0±8.55ns 479.6±18.35ns +0.76%
parent_decl_at_position 3.6±0.04ms 3.6±0.03ms 0.00%
prepare_rename 357.9±6.44µs 371.0±6.99µs +3.66%
rename 9.1±0.03ms 9.2±0.18ms +1.10%
semantic_tokens 1047.1±44.57µs 1063.9±31.48µs +1.60%
token_at_position 349.7±1.71µs 373.4±2.78µs +6.78%
tokens_at_position 3.6±0.08ms 3.6±0.07ms 0.00%
tokens_for_file 407.9±2.01µs 412.4±7.28µs +1.10%
traverse 37.6±1.66ms 38.3±1.03ms +1.86%

Copy link

github-actions bot commented Mar 4, 2024

Benchmark for 68cbbec

Click to view benchmark
Test Base PR %
code_action 5.2±0.08ms 5.1±0.10ms -1.92%
code_lens 308.3±7.71ns 338.0±10.03ns +9.63%
compile 4.4±0.15s 4.4±0.06s 0.00%
completion 4.8±0.06ms 4.8±0.08ms 0.00%
did_change_with_caching 3.7±0.02s 3.6±0.03s -2.70%
document_symbol 1019.6±39.57µs 958.7±15.63µs -5.97%
format 74.1±0.75ms 73.2±0.58ms -1.21%
goto_definition 360.1±8.28µs 363.7±14.36µs +1.00%
highlight 8.7±0.03ms 8.8±0.20ms +1.15%
hover 528.6±6.32µs 541.5±7.42µs +2.44%
idents_at_position 121.9±1.55µs 121.4±0.64µs -0.41%
inlay_hints 651.7±21.14µs 654.6±18.32µs +0.44%
on_enter 486.5±13.50ns 482.6±11.97ns -0.80%
parent_decl_at_position 3.6±0.05ms 3.6±0.04ms 0.00%
prepare_rename 362.5±7.26µs 368.3±7.11µs +1.60%
rename 9.3±0.31ms 9.2±0.16ms -1.08%
semantic_tokens 1083.7±15.68µs 1068.2±25.80µs -1.43%
token_at_position 358.9±9.78µs 359.1±2.31µs +0.06%
tokens_at_position 3.6±0.03ms 3.6±0.05ms 0.00%
tokens_for_file 408.0±1.93µs 408.5±3.01µs +0.12%
traverse 39.3±2.29ms 39.3±0.72ms 0.00%

crodas and others added 8 commits March 5, 2024 16:28
Fixes #5633

Added functionality to create and manage a lock file containing the process ID
(pid) of the running instance of the software. This mechanism prevents multiple
instances of the software from running simultaneously by checking the existence
and content of the lock file. If the lock file exists and contains a valid pid,
the struct will error gracefully to avoid conflicts. If the lock file is
missing or contains an invalid pid, the struct will proceed by removing the
file.  This ensures that only one instance of the software can run at a time
and it avoids stale locking to prevent future instances
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com>
@crodas crodas requested review from JoshuaBatty, sdankel and a team March 5, 2024 19:29
Copy link

github-actions bot commented Mar 5, 2024

Benchmark for 2fe0c97

Click to view benchmark
Test Base PR %
code_action 5.3±0.01ms 5.3±0.08ms 0.00%
code_lens 286.0±7.22ns 289.8±9.16ns +1.33%
compile 4.4±0.05s 4.3±0.13s -2.27%
completion 4.8±0.04ms 4.8±0.07ms 0.00%
did_change_with_caching 3.9±0.13s 3.8±0.12s -2.56%
document_symbol 1063.5±27.26µs 949.6±17.40µs -10.71%
format 72.7±1.23ms 73.3±1.12ms +0.83%
goto_definition 362.1±4.03µs 366.9±8.98µs +1.33%
highlight 9.0±0.22ms 9.1±0.18ms +1.11%
hover 542.6±33.33µs 535.6±14.32µs -1.29%
idents_at_position 122.8±0.52µs 121.6±1.14µs -0.98%
inlay_hints 668.4±23.92µs 670.6±30.53µs +0.33%
on_enter 477.2±13.17ns 475.0±17.86ns -0.46%
parent_decl_at_position 3.7±0.03ms 3.7±0.03ms 0.00%
prepare_rename 362.4±21.57µs 365.6±5.89µs +0.88%
rename 9.4±0.18ms 9.4±0.13ms 0.00%
semantic_tokens 1058.6±11.57µs 1051.6±39.30µs -0.66%
token_at_position 361.3±3.01µs 367.6±3.43µs +1.74%
tokens_at_position 3.7±0.03ms 3.7±0.10ms 0.00%
tokens_for_file 421.3±3.62µs 426.1±2.45µs +1.14%
traverse 37.6±0.81ms 38.1±1.43ms +1.33%

Copy link

github-actions bot commented Mar 5, 2024

Benchmark for 3f190bf

Click to view benchmark
Test Base PR %
code_action 5.4±0.16ms 5.4±0.11ms 0.00%
code_lens 285.8±16.00ns 299.8±24.10ns +4.90%
compile 4.2±0.07s 4.3±0.14s +2.38%
completion 4.8±0.07ms 4.8±0.13ms 0.00%
did_change_with_caching 3.7±0.11s 3.7±0.10s 0.00%
document_symbol 958.1±21.79µs 1024.3±15.95µs +6.91%
format 73.0±1.28ms 72.7±0.68ms -0.41%
goto_definition 359.8±6.33µs 357.3±6.44µs -0.69%
highlight 9.1±0.19ms 9.1±0.23ms 0.00%
hover 537.4±11.21µs 523.3±4.71µs -2.62%
idents_at_position 121.6±0.82µs 121.4±0.88µs -0.16%
inlay_hints 658.0±22.88µs 661.4±23.72µs +0.52%
on_enter 471.1±9.34ns 470.8±13.34ns -0.06%
parent_decl_at_position 3.7±0.07ms 3.7±0.06ms 0.00%
prepare_rename 362.5±10.50µs 381.1±6.40µs +5.13%
rename 9.5±0.26ms 9.5±0.27ms 0.00%
semantic_tokens 1049.7±13.48µs 1034.9±25.35µs -1.41%
token_at_position 370.9±2.02µs 346.7±3.92µs -6.52%
tokens_at_position 3.7±0.05ms 3.7±0.03ms 0.00%
tokens_for_file 421.5±4.69µs 418.6±7.71µs -0.69%
traverse 37.4±1.37ms 38.1±0.91ms +1.87%

Copy link

github-actions bot commented Mar 6, 2024

Benchmark for b777769

Click to view benchmark
Test Base PR %
code_action 5.4±0.14ms 5.3±0.16ms -1.85%
code_lens 292.2±44.82ns 296.8±8.82ns +1.57%
compile 4.3±0.04s 4.2±0.09s -2.33%
completion 4.9±0.11ms 4.9±0.09ms 0.00%
did_change_with_caching 3.8±0.12s 3.9±0.13s +2.63%
document_symbol 1022.7±42.96µs 957.5±8.19µs -6.38%
format 73.1±1.11ms 73.0±1.30ms -0.14%
goto_definition 361.2±6.28µs 371.9±36.86µs +2.96%
highlight 9.1±0.16ms 9.0±0.02ms -1.10%
hover 537.2±19.01µs 543.6±18.50µs +1.19%
idents_at_position 121.6±0.44µs 122.8±0.65µs +0.99%
inlay_hints 663.5±41.07µs 666.8±32.23µs +0.50%
on_enter 475.7±8.44ns 487.9±19.03ns +2.56%
parent_decl_at_position 3.7±0.03ms 3.7±0.04ms 0.00%
prepare_rename 358.6±6.67µs 368.4±17.30µs +2.73%
rename 9.5±0.19ms 9.4±0.23ms -1.05%
semantic_tokens 1031.8±12.20µs 1061.8±16.87µs +2.91%
token_at_position 354.3±3.06µs 362.0±2.55µs +2.17%
tokens_at_position 3.7±0.06ms 3.7±0.02ms 0.00%
tokens_for_file 417.3±2.85µs 420.1±2.22µs +0.67%
traverse 37.4±0.89ms 38.5±1.49ms +2.94%

Copy link

github-actions bot commented Mar 6, 2024

Benchmark for 047bb2a

Click to view benchmark
Test Base PR %
code_action 5.6±0.18ms 5.5±0.09ms -1.79%
code_lens 292.4±7.11ns 289.7±8.83ns -0.92%
compile 6.1±0.11s 6.0±0.08s -1.64%
completion 5.3±0.14ms 5.0±0.20ms -5.66%
did_change_with_caching 5.3±0.12s 5.4±0.04s +1.89%
document_symbol 1038.3±65.27µs 988.0±40.96µs -4.84%
format 72.8±3.54ms 71.3±1.46ms -2.06%
goto_definition 366.3±7.06µs 365.3±3.76µs -0.27%
highlight 9.4±0.89ms 9.1±0.06ms -3.19%
hover 595.1±18.42µs 596.9±60.29µs +0.30%
idents_at_position 123.1±0.37µs 124.5±0.63µs +1.14%
inlay_hints 672.8±24.03µs 674.4±18.00µs +0.24%
on_enter 516.7±11.52ns 501.1±18.15ns -3.02%
parent_decl_at_position 3.8±0.06ms 3.7±0.05ms -2.63%
prepare_rename 362.8±10.92µs 363.6±10.78µs +0.22%
rename 9.7±0.24ms 9.6±0.18ms -1.03%
semantic_tokens 1072.9±13.52µs 1031.9±19.19µs -3.82%
token_at_position 357.3±2.82µs 352.0±2.86µs -1.48%
tokens_at_position 3.8±0.06ms 3.7±0.03ms -2.63%
tokens_for_file 418.8±4.15µs 410.3±2.00µs -2.03%
traverse 44.5±1.20ms 43.8±1.84ms -1.57%

@crodas crodas merged commit c1c2501 into master Mar 6, 2024
32 checks passed
@crodas crodas deleted the lsp-lock-stale-recovery branch March 7, 2024 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle removing the lsp-lock file in cases of non graceful IDE shutdown
3 participants