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

Fix PrettierAsync segmentation fault #138

Merged
merged 2 commits into from
May 25, 2018
Merged

Fix PrettierAsync segmentation fault #138

merged 2 commits into from
May 25, 2018

Conversation

SamHowie
Copy link
Collaborator

@SamHowie SamHowie commented May 25, 2018

Summary

This pull request fixes #135 where the command PrettierAsync causes Vim to crash due to segmentation fault.

The following is a summary of the involved fixes:

Transportation fix:

  1. Change the jobs in_io back to the default of pipe
  2. Read the selected buffer lines and write them to the jobs channel
  3. Close the in channel to tell the job we have finished sending

Performance fix:

  1. Use a simpler method to delete all lines in the buffer
  2. Loop through and append all the lines we want to write to the buffer

Test Plan

Error Reproduction Steps:

  1. Copy the crash.js file from @nerfologist reproduction example - https://raw.githubusercontent.com/nerfologist/vim-prettier-async-segv-bug/master/crash.js
  2. Open crash.js in vim
  3. Execute PrettierAsync
  4. Notice the seg fault!

NOTE: If the seg fault doesn't occur, increase the number of lines calling someFunc('something', () => {});. Eventually you will reach your platforms magic buffer size to cause the seg fault.

Test Steps For Fix:

  1. Clone pull request commit
  2. Copy the crash.js file from @nerfologist reproduction example - https://raw.githubusercontent.com/nerfologist/vim-prettier-async-segv-bug/master/crash.js
  3. Open crash.js in vim
  4. Execute PrettierAsync
  5. Notice there is no seg fault!
  6. Make the file much bigger and try again
  7. Notice there is still no seg fault!

@SamHowie
Copy link
Collaborator Author

SamHowie commented May 25, 2018

Please note: I have not tested this fix on NeoVim. The only changes that overlap with that code path relate to the performance fixes in s:Apply_Prettier_Format

@SamHowie SamHowie requested a review from mitermayer May 25, 2018 04:38
@mitermayer
Copy link
Member

I think this looks good to me feel free to merge this once we test neovim and vim 7.4 sync formatting.

@mitermayer
Copy link
Member

I have just tested this out on vim 7.4, vim8 and neovim for regression and most of it worked, the only regression that I noticed is that after your change we seem to get an extra line on the end of the file.

Once that is fixed this should be good to go!

@SamHowie
Copy link
Collaborator Author

I just pushed a fix to remove the extra trailing newline introduced by using the append function.

Looks good on Vim 8. Please confirm Vim 7.4 and NeoVim.

Thanks!

@mitermayer
Copy link
Member

Looks good on neovim and vim 7

@mitermayer mitermayer merged commit 01c6928 into prettier:master May 25, 2018
@mitermayer mitermayer mentioned this pull request May 25, 2018
13 tasks
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.

Vim crashes with segmentation fault with PrettierAsync
2 participants