Skip to content

Commit

Permalink
Fix crash: posting Vim message from thread
Browse files Browse the repository at this point in the history
Vim is not thread-safe so posting a message to Vim from a non-GUI thread causes
a crash *sometimes*. I was aware of this problem before, but didn't catch this
instance of it in code review.

Fixes #479.
  • Loading branch information
Valloric committed Jul 30, 2013
1 parent f347885 commit 4374da6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 3 additions & 4 deletions python/ycm/completers/cs/cs_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,9 @@ def _GetResponse( self, endPoint, parameters={}, silent = False ):
try:
response = urllib2.urlopen( target, parameters )
return json.loads( response.read() )
except Exception as e:
if not silent:
vimsupport.PostVimMessage(
'OmniSharp : Could not connect to ' + target + ': ' + str( e ) )
except Exception:
# TODO: Add logging for this case. We can't post a Vim message because Vim
# crashes when that's done from a no-GUI thread.
return None


Expand Down
4 changes: 4 additions & 0 deletions python/ycm/vimsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def NumLinesInBuffer( buffer ):


def PostVimMessage( message ):
# TODO: Check are we on the main thread or not, and if not, force a crash
# here. This should make it impossible to accidentally call this from a
# non-GUI thread which *sometimes* crashes Vim because Vim is not thread-safe.
# A consistent crash should force us to notice the error.
vim.command( "echohl WarningMsg | echomsg '{0}' | echohl None"
.format( EscapeForVim( message ) ) )

Expand Down

0 comments on commit 4374da6

Please sign in to comment.